Ajax Async Synchronous and asynchronous detailed _jquery in jquery

Source: Internet
Author: User

There is a requirement in the project to load the data using AJAX to return the page and assign the value, and then the front end to remove the value

This involves the sequence of code issues, sometimes the background has not returned data, but has executed the following code,

So it's going to take the value out.

$.ajax ({type: "post",  URL: "Admin/pfmoptionruleitem.do", success:function (data) {  $ ("#ruleItem"). Val ( Data.ruleitem); ①}}); Return $ ("#ruleItem"). Val (); Ii

If ① has not returned data from the background, then the execution ② is not getting the value

The first letter of Ajax is the asynchronous letter, which means that all operations are parallel and the order of completion is not related.

The async parameter of $.ajax () is always set to true, which indicates that other code can still be executed after the request has started.

If you set this option to false, this means that all requests are no longer asynchronous, which can also cause the browser to be locked.

Although the official does not recommend this, but can not use too much, otherwise it will result in poor user experience

Give me a chestnut.

Alert ("Setp 1"); $.ajax ({  URL: "admin/pfmoptionruleitem.do",  Async:false,  success:function (data) {   alert ("Hello Ajax "); ①  }}); Alert ("Setp 2"); Ii

When the Asyn is set to False, the AJAX request is synchronized, that is, when the Ajax block makes a request,

He would wait in ① this place, would not go down to execute ② until ① finished

This is done sequentially

SETP 1

Hello Ajax

SETP 2

If Async is true, the execution order is

SETP 1

SETP 2

Hello Ajax

About this article to everyone described in the jquery Ajax async Synchronous and asynchronous, all introduced, I hope to help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.