Solved

First Ajax jQuery example

Posted on 2011-09-19
6
270 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…

939 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