Home  >  Article  >  Web Front-end  >  $.ajax async based on jquery using _jquery

$.ajax async based on jquery using _jquery

WBOY
WBOYOriginal
2016-05-16 18:00:49694browse

(Default: true) By default, all requests are asynchronous. If you need to send synchronous requests, set this option to false. Note that a synchronous request will lock the browser, and the user must wait for the request to complete before other operations can be performed.

Copy code The code is as follows:

var temp;
$.ajax({
async: false,
type : "POST",
url : defaultPostData.url,
dataType : 'json',
success : function(data) {
temp=data;
}
});
alert(temp);

This ajax request is a synchronous request. Alert(temp) will not be executed until there is no return value. .
If async is set to: true, it will not wait for the result returned by the ajax request, but will directly execute the statement following the ajax.
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