Recently, using jquery Ajax, we found that some effects were incorrect, and the JSON string returned after the Ajax request came back, but there was a problem with the order of execution.
var false ; $.post ('/home/detectcachedlogininfor/',function (result) {if ( result.errormsg) {iftrue' json '); if (isreload) {openreloginform (); return false ;}
It is found that the returned number is result.errormsg, but Isreload cannot give the assignment true, the following if (Isreload) {...} cannot be executed smoothly
The final discovery is the asynchronous execution order of the post, so the following research is done, and a summary is written
--------because the post defaults to an asynchronous request, the data is returned asynchronously instead of sequentially executing until the data is returned before the next step is performed.
So we'll get the value of the method, Ajax--async:false can
varIsreload =false; $.ajax ({URL:'/home/detectcachedlogininfor/', Async:false,//Note that synchronization is required here, because after the data is returned, the first bar of the result is selectedType: "POST", DataType:"JSON", Success:function(Result) {if(result.errormsg) {alert (result.errormsg); isreload =true; }}});if(isreload) {openreloginform ();return false;}
jquery Ajax asynchronous and synchronous from the acquired value