Home  >  Article  >  Web Front-end  >  How does ajax in jquery return results instead of callbacks and execute them in the same order?

How does ajax in jquery return results instead of callbacks and execute them in the same order?

亚连
亚连Original
2018-05-25 16:06:011300browse

The default ajax is asynchronous, that is, the downward execution will not be affected when the result is not responded to. If you must return the result, change the async parameter in ajax to false, which means execution in the same order.

Because the default ajax is asynchronous, that is, the downward execution will not be affected when the result is not responded to. So it must be implemented using callbacks. This solution is more efficient.
If you must return the result, change the async parameter in ajax to false, which means executing it in the same order. Implement the following to return the result.
However, this approach is not recommended unless necessary.

function(url,params){ 
var outdata; 
$.ajax({ 
type : "get", 
async:false, 
dataType:"json", 
url : url, 
data: params, 
success : function(data){ 
outdata = data; 
}, 
error:function(e){ 
alert('ajax error'); 
} 
}); 
return outdata; 
}

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

The problem that IE8 cannot refresh every time when using ajax access

Ajax cache under IE8/IE9 Problem

Ajax cache problem and solution under IE8

The above is the detailed content of How does ajax in jquery return results instead of callbacks and execute them in the same order?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn