主线程上的同步 XMLHttpRequest 已弃用,因为它会对最终用户的体验产生不利影响
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience
我正在使用 $.load 从其他本地页面加载内容,但我在 chrome 和 firefox 中都收到此错误。
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience
这是我的代码
$(document).on("click", ".menuL", function() {
var e = $(this).attr("href");
$(".main").html('<center><img src="img/loader.gif" /></center>');
$(".main").load(e + session, function(response, status, xhr){
if(status == "error") {
window.location.href = '/home';
}
});
return false
});
我用谷歌搜索了所有可能的解决方案,但所有解决方案都引导我做同样的事情,将 async 设置为 true 但我该怎么做?
由于 $.load()
只是普通 $.ajax()
调用的简化函数,您可以使用 $.ajaxPreFilter()
在发送每个请求之前以及在它们被处理之前设置特定选项$.ajax()
.
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
options.async = true;
});
默认情况下,这设置为 true
并且不会更改,除非您在代码的其他地方进行了设置。
我正在使用 $.load 从其他本地页面加载内容,但我在 chrome 和 firefox 中都收到此错误。
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience
这是我的代码
$(document).on("click", ".menuL", function() {
var e = $(this).attr("href");
$(".main").html('<center><img src="img/loader.gif" /></center>');
$(".main").load(e + session, function(response, status, xhr){
if(status == "error") {
window.location.href = '/home';
}
});
return false
});
我用谷歌搜索了所有可能的解决方案,但所有解决方案都引导我做同样的事情,将 async 设置为 true 但我该怎么做?
由于 $.load()
只是普通 $.ajax()
调用的简化函数,您可以使用 $.ajaxPreFilter()
在发送每个请求之前以及在它们被处理之前设置特定选项$.ajax()
.
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
options.async = true;
});
默认情况下,这设置为 true
并且不会更改,除非您在代码的其他地方进行了设置。