tags:

views:

191

answers:

4

Hello All

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.

+2  A: 

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
        }

     }));
jacobangel
+5  A: 

If you copied-n-pasted the code in your example, you have async misspelled aysnc. Without that option, it will run asynchronously.

Adam Bellaire
A: 

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 :)

Stack Overflow is not like a forum. You should now mark his answer as accepted, and probably give him some reputation for it.
Manuel Ferreria
+1  A: 

if your using the $.ajax method and you want to your sucess function you should set the dataType option to xml.

bendewey