Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Asynchronous and synchronous in Ajax request

Shulou Source: shulou.com Published: 2022-06-03 05:38:32 11月17日 Update

This article mainly shows you "sample analysis of asynchronism and synchronization in Ajax requests". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "sample analysis of async and synchronization in Ajax requests".

When I was working on the project, I used a table control whose data was loaded asynchronously. I did some business processing under the function of binding data in this table. When I was running the page, I used the browser to put breakpoint tracking in the place where I wrote the business processing. It did execute. When it was finally displayed, its processing was overwritten. I was very puzzled. At that time, I also knew that there was a problem with this table binding function, but time was tight, and its function was encapsulated. Without specific tracking, I directly let that part of my business process delay the execution of 200ms. This is good, this is a stupid method, but it is also an effective way, hehe.

Later, I looked at the document and looked up some information. In fact, the principle should be like this:

By default, all requests are asynchronous. If you need to send a synchronization request, set this option to false. Note that the synchronization request will lock the browser, and other user actions must wait for the request to complete.

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, and alert (temp) is not executed until there is no return value.

If async is set to: true, the result of the ajax request will not be waited, and the statement that follows the ajax will be executed directly.

The above is all the contents of the article "sample Analysis of asynchronism and synchronization in Ajax requests". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Synchronization processing examples analysis content function time article table business data browser learning help browsing tracking effectiveness code method principle Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology Linux MySQL Xiaomi