Ajax requests are divided into synchronous requests and asynchronous requests, but the default ones are asynchronous requests. So, when we want to use ajax to request synchronously, how should we implement this synchronous request? The following article will introduce to you the implementation of ajax synchronization request. Friends in need can refer to it. I hope it will be helpful to you.
First of all, we should know that synchronization is a single thread, and the code is executed in order. When the js code is loaded into the current synchronous ajax request, all other codes on the page stop loading, and the page is in a state of suspended animation. , until the request is completed, other requests will be executed.
Secondly, we should know that ajax is divided into two request methods: synchronous and asynchronous according to the value of async. When the value of async is true, it is the asynchronous request method. On the contrary, when the value of async is false, it is the asynchronous request method. Synchronous request method, so to implement ajax synchronous request, you only need to set the value of async to false.
The code for ajax to implement synchronous requests is as follows:
$.ajax( type:“POST”/“GET” url:"", data:{}, dataType:"json", async:false,//同步 success:function(response){ } );
The above is the detailed content of How to implement synchronous request in ajax? Ajax method to implement synchronous request. For more information, please follow other related articles on the PHP Chinese website!