views:

464

answers:

1

I have a code snippet like this

var searchurl="http://mysite.com/searchpath?q=test";
$.ajax({
   type: "GET",
   url: searchurl,
   cache: false,
   dataType : "jsonp",
   async : false,
   success: function(data){
        alert("success");
   }
});
alert("outside ajax");

The problem is that I am not seeing async at work. "outside ajax" is the first popup i get and "success" the second. is there something obvious that I am missing?

Adding from my comments to Anothny's reply

My test env is win xp sp2, FF 3.0.8/w Firebug + IE 8. and JQuery v1.3.2 . There is nothing obvious I was able to find from the firebug.

Would you be willing to try above code with with this url "http://pipes.yahoo.com/pipes/pipe.run?_id=1nWYbWm82xGjQylL00qv4w&_render=json&textinput1=obama&_callback=?"

+3  A: 

Well, you cannot have a synchronous jsonp request. The way jsonp is implemented is through a script tag hack to allow cross-domain access. So $.ajax simply ignores the async attribute because it just cannot make a synchronous jsonp request.

As a side note, you should try & avoid synchronous ajax requests. Though they may seem simpler in design at first, they end up freezing browsers in case of network retention and make for a very unpleasant user experience.

Julian Aubourg