Reputation:
I am new to jQuery and I am using ajax request to get an xml as response,
$.get("testurl",pars,function(data){
xml = data;
$(xml).find("element").each(function(i,item){
if(($(this).attr("id"))!= undefined){
tab_str += "<tr><td>'id'</td><td>"+$(this).attr("id")+"</td></tr>";
}
});
});//get
In the above code I get the xml back as expected. The only problem is I need to completely construct my table before the rest of the code executes. So I decided to use the $.ajax function with async false. But this time I am not getting anything back. (I check the firebug console, it shows the complete xml in the response section)
var xml = ( $.ajax({
type: "GET",
url: "testurl",
data: pars,
aysnc:false
}).responseText);
In the code above the var xml is empty. Why is this? am I doing something wrong? Please help. Thanks in advance.
Upvotes: 1
Views: 310
Reputation: 40235
if your using the $.ajax method and you want to your sucess function you should set the dataType option to xml.
Upvotes: 1
Reputation:
God I feel so stupid Adam thanks for pointing out. I would not have managed to catch it atleast not today :)
yeah I was using 'aysnc' instead of 'async'
btw I need to mention I love this forum. I just stepped out for a coffee and I have two responses...wow! you guys rock. Thanks a ton for the quick response.
jdangel: I tried that too obviously it did not work :)
Upvotes: 0
Reputation: 110429
If you copied-n-pasted the code in your example, you have async
misspelled aysnc
. Without that option, it will run asynchronously.
Upvotes: 5
Reputation: 6996
I would guess your response isn't returning quickly enough? Have you tried setting the xml using the success: parameter?
( $.ajax({
type: "GET",
url: "testurl",
data: pars,
aysnc:false
success: function () {
//set the right stuff here
}
}));
Upvotes: 2