Home > Web Front-end > Front-end Q&A > Is jquery ajax synchronous or asynchronous by default?

Is jquery ajax synchronous or asynchronous by default?

WBOY
Release: 2022-09-08 17:42:03
Original
2174 people have browsed it

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.

Is jquery ajax synchronous or asynchronous by default?

The operating environment of this article: Windows 10 system, jquery version 3.6.1, Dell G3 computer.

Is jquery ajax synchronous or asynchronous by default?

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

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!

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