Synchronous and asynchronous jquery-Ajax

Source: Internet
Author: User
//  Verify supplier $ ("# Providerid"). ATTR ("value ",""); //  Clear  $. Ajax ({URL: '$ {Path}/product/findbyproviderid' , Async:  False , //  Synchronization Type: 'post' , Data: {qc_provider_name: $ ( "# Qc_provider_name"). Val ()}, datatype: 'Text' , Success:  Function  (Result) {$ ( "# Providerid" ). Val (result );}});  If ($ ("# Providerid"). Val () = "" ) {Alert ( "The supplier does not exist" );  Return   False ;} 

Upper sectionCodeIs a part of JS. Previously, Ajax's async: false was not added. If not,ProgramAjax is asynchronous by default, that is, the two pieces of code do not affect each other. Then, a dialog box is always displayed, indicating that the supplier does not exist. I said it is strange. In the success attribute, the result value is displayed, there is a value, and then a javascript variable is set to accept the value of result, there is a value in it, not outside, get a hidden input accept value is also a value in the execution, there is no value outside. I checked it and did not add a synchronization ID.

Ajax is asynchronous by default, that is, when the above code is executed, the following code is also executed at the same time, and the above result code is still being executed, the code for the variable assigned by the result value is also being executed. Of course, it is empty. After the synchronization identifier is added, the code is executed in sequence and OK. Previously, it was used in that way and never thought about synchronous and asynchronous. Note:

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.