Solved

First Ajax jQuery example

Posted on 2011-09-19
6
272 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…

830 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