jquery Ajax, when Async is false, the sync operation fails. Solutions, Jqueryasync
Recently do project encounter jquery Ajax, when Async is false, sync operation failure problem, the Internet search, get a solution, here on how to solve:
Code when a failure is thrown:
$.ajax ({
URL: ' Your URL ',
data:{name:value},
Cache:false,
async:true,
type: "POST",
DataType: ' json/xml/html ',
success:function (result) {return result
}
});
Solution:
var ret = null;
$.ajax ({
URL: ' Your URL ',
data:{name:value},
Cache:false,
async:true,
type: "POST",
dataType: ' json/xml/html ',
success:function (result) {
ret=result;
}
});
return ret;
Description
Do not return directly in the success callback function, the specific reason behind in the investigation!!
$ajax () Set the synchronization commit is invalid, the code below, set async: "False" but still asynchronous commit
Ajax was intended for asynchronous operations, and the latest jquery version has even deprecated async parameters.
If you just want to use Ajax to do server interaction, do not need an asynchronous refresh effect, that can use the callback function.
jquery $ajax function, async in: "False" does not work to help look at
"false" adds double quotes as a string, and a non-empty string is true.
Remove the double quotes.
Thank you for reading, I hope to help you, thank you for your support for this site!