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)