Home > Web Front-end > JS Tutorial > body text

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

亚连
Release: 2018-05-25 16:06:01
Original
1390 people have browsed it

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; 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!