Solved

First Ajax jQuery example

Posted on 2011-09-19
6
269 Views
Last Modified: 2012-05-12
Ive been trying to get my first ajax jQuery code working and about to give up. I cannot figure out what it wrong, and it doesnt seem to be pussing any errors.

The code I think is quite simple, that is pull in the file test.html and stick the contents into the div with the ID 'result', however it doenst ever seem to fire.

<head>
    <title></title>
    <script type="text/javascript" src="..\jquery-1.6.4.js"></script>

    <script type="text/javascript">
        $(".trigger").click(function() {
            $.ajax({
                type: 'GET',
                url: 'test.htm',
                dataType: 'html',
                sucess: function(html, textStatus) {
                    $(".result").append(html);
                    },
                error: function (xhr, textStatus, errorThrown) {
                    $(".error").append(errorThrown ? errorThrown : xhr.status);
                    }
                })
            });
    </script>
</head>
<body>
<div id="trigger">Trigger</div>
<div id="result"></div>
<div id="error"></div>
</body>
</html>

Open in new window



Any ideas what Im doing wrong :-S
0
Comment
Question by:tonelm54
6 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 36560269
You code try to use class instead id :
<div id="result"></div>
<div id="error"></div>

should be :
<div class="result"></div>
<div class="error"></div>

or replace << . >> by << # >> in your selectors to use ID
0
 
LVL 20

Assisted Solution

by:chaitu chaitu
chaitu chaitu earned 125 total points
ID: 36560277
$("#result").append(html);
 $("#error").append(errorThrown ? errorThrown : xhr.status);
0
 
LVL 6

Assisted Solution

by:limweizhong
limweizhong earned 125 total points
ID: 36560365
Just a guess here: you spelled "success" wrongly...?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:tonelm54
ID: 36560665
Ok, so spelling mistakes corrected, and # replaced with ', but still doesnt work :-(

<head>
    <title></title>
    <script type="text/javascript" src="..\jquery-1.6.4.js"></script>

    <script type="text/javascript">
        $("#trigger").click(function() {
            $.ajax({
                type: 'GET',
                url: 'test.htm',
                dataType: 'html',
                success: function(html, textStatus) {
                    $("#result").append(html);
                    },
                error: function (xhr, textStatus, errorThrown) {
                    $("#error").append(errorThrown ? errorThrown : xhr.status);
                    }
                })
            });
    </script>
</head>
<body>
<div id="trigger">Trigger</div>
<div id="result"></div>
<div id="error"></div>
</body>
</html>

Open in new window


Any ideas?
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 36560687
0
 

Author Closing Comment

by:tonelm54
ID: 36561068
Excellent, thank you for you help :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now