Jquery synchronous request and asynchronous request (execution order)

Source: Internet
Author: User
Function  Show (noticeid) {$. Post ( 'Noticeshow. aspx? Operate = getdetail '+' & noticeid = '+ noticeid +' & id = '+ math. Random (), Function (Notice ){ //  First                  If (Notice! = Null ){ //  Get the returned JSON and assign a value $ ("# Txtnoticetitle" ). Val (Notice. noticetitle); $ ( "# Txtnoticecontent"). Val (Notice. noticecontent); $ ( "# Lblnoticetype" Pai.html (Notice. noticetype); $ ( "# Txtremark" ). Val (Notice. remark );}}, 'Json' ); $ ( '# Show'). Window ("open "); //  Second $ ('# Show'). Show (); //  Third }

 

Such a request is asynchronous, and the result is ordered as follows: Second. After the execution is complete, the first result is returned. But I want him to return the result first, and then execute the second and third operations.

$. Post and $. Get I have not found how to set synchronization, but $. Ajax can

         Function Show (noticeid) {$. Ajax ({type: "Post" , URL: 'Noticeshow. aspx? Operate = getdetail '+' & noticeid = '+ noticeid +' & id = '+ Math. Random (), async:  False , //  If it is set to false, the request is synchronized. Cache: False  , Success:  Function  (Notice ){  If (Notice! =Null ){ //  Get the returned JSON and assign a value $ ("# Txtnoticetitle" ). Val (Notice. noticetitle); $ ( "# Txtnoticecontent" ). Val (Notice. noticecontent); $ ( "# Lblnoticetype" Pai.html (Notice. noticetype); $ ( "# Txtremark" ). Val (Notice. remark) ;}}); $ ( '# Show'). Window ("open" ); $ ( '# Show'). Show ();} 

The execution sequence is synchronous: The request returns the result before executing the following. (PS: it seems easy to get stuck)

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.