async:false option not working in $.ajax() , is it depreciated in jQuery 1.8+ for all use cases? -


i'm confused using async: false option $.ajax(). according $.ajax() documentation:

as of jquery 1.8, use of async: false jqxhr ($.deferred) deprecated; must use success/error/complete callback options instead of corresponding methods of jqxhr object such jqxhr.done() or deprecated jqxhr.success().

i don't know jqxhr ($.deferred) means. using async:false reason depreciated, or jqxhr ($.deferred) sort of special use case?

i ask i'm having trouble getting $.ajax() call happen asynchronously.this jquery 1.8.2:

var ret = {};  $.ajax({    async:           false,     method:         'get',     contenttype:    'application/json',     datatype:       'jsonp',     url:            '/couchdbserver',     error:          myerr,     success:        function(data) {          var rows = data.rows;          //something takes long time         for(var row in rows) {              ret[rows[row].key] = rows[row].value;         }          console.log('tick');     } }); console.log('tock'); console.log(json.stringify(ret)) 

my console output is:

tock
{}
tick

am doing wrong, or doing wrong?

you trying use jsonp techinque async:false @ same time. not possible. jsonp creating script element , appending somewhere document, it's not xhr , jquery can't pass sync flag anywhere. since data same origin, change datatype

datatype:       'json', 

however, can tell synchronous requests not hang browser. should use them in small number of cases.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -