I'm confused about using the async: false option with $.ajax(). According to the $.ajax() documentation:
As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated;
you must use the success/error/complete callback options instead of the corresponding
methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().
I don't know what jqXHR ($.Deferred) means. Is using async:false for any reason depreciated, or is jqXHR ($.Deferred) some sort of special use case?
I ask as I'm having trouble getting an $.ajax() call to happen asynchronously.This is with 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 that takes a 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 I doing something wrong, or am I doing something wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…