我想知道如果我发送这样的 ajax 请求,为什么会出现此错误:
$.ajax({
url: "testOperation.php",
async: false,
data: compareHeure,
success: function (data, statusRequest) {
})
错误:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
有问题吗?
谢谢,
最佳答案
我想知道为什么会出现此错误
简短的回答是因为 ajax 中的这个选项:
async: false,
对于您当前遇到的问题,可能还有其他更好的解决方案。如果您发布有关为什么需要使用同步 ajax 的更多详细信息?
要么这样使用:
$.ajax({
url:'',
type:'post',
success:function(data){
// make another ajax call here then
}
})
你可以使用jQuery.when()
:
$.when( $.ajax("/page1.php"), $.ajax("/page2.php") ).done(function(a1, a2) {
// here you can get both ajax response when both gets completed.
console.log(a1);
console.log(a2);
});
此处 .done()
仅在两个 ajax 都完成时执行。
关于javascript - jQuery Ajax 请求异步 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37938682/