In jquery, ajax is an asynchronous request by default, that is, "async:true"; depending on the async value, you can determine whether it is an asynchronous request. If the async value is false, it means that the ajax request is synchronous , if the value of async is true, it means that the ajax request is asynchronous.
The operating environment of this article: Windows 10 system, jquery version 3.6.1, Dell G3 computer.
Ajax in jquery is an asynchronous request by default, that is, async:true. You can make it synchronous by setting the parameter asycn:false
ajax defaults to an asynchronous request; in ajax, you can determine whether it is an asynchronous request based on the different async values. If the value of async is false, it means that the ajax request is synchronous. If the value of async is true, it means that the ajax request is asynchronous. , and by default the value of async is "true", so ajax is an asynchronous request by default.
$.ajax({ url: 'www.test.com/test/test', type: 'POST', data: {name:"test"} async: false, error: function() { console.log('error'); }, success: function(resp) { console.log('success'); } });
Note: If you have this kind of operation. I wrote a flag = false before calling ajax; but operations such as setting flag = true in the success callback of ajax cannot get the desired result in the asynchronous state of ajax.
Because ajax is asynchronous by default, it is possible to execute the callback flag = true operation after you complete the subsequent operations! !
Recommended related tutorials: jQuery video tutorial
The above is the detailed content of Is jquery ajax synchronous or asynchronous by default?. For more information, please follow other related articles on the PHP Chinese website!