我一直在向控制台添加日志,以检查不同变量的状态,而不使用Firefox调试器。
然而,在我在main.js文件中添加console.log的许多地方,我收到了以下错误,而不是我给自己的可爱的手写消息:
主线程上的同步XMLHttpRequest已弃用,因为它会对最终用户的体验产生不利影响。更多帮助http://xhr.spec.whatwg.org/
我可以在我的代码使用中添加哪些不会导致此错误的console.log替代品或包装器?
我“做错了”吗?
我一直在向控制台添加日志,以检查不同变量的状态,而不使用Firefox调试器。
然而,在我在main.js文件中添加console.log的许多地方,我收到了以下错误,而不是我给自己的可爱的手写消息:
主线程上的同步XMLHttpRequest已弃用,因为它会对最终用户的体验产生不利影响。更多帮助http://xhr.spec.whatwg.org/
我可以在我的代码使用中添加哪些不会导致此错误的console.log替代品或包装器?
我“做错了”吗?
当前回答
警告消息可能是由于主线程中的XMLHttpRequest请求将async标志设置为false。
https://xhr.spec.whatwg.org/ synchronous:
Synchronous XMLHttpRequest outside of workers is in the process of being removed from the web platform as it has detrimental effects to the end user's experience. (This is a long process that takes many years.) Developers must not pass false for the async argument when the JavaScript global environment is a document environment. User agents are strongly encouraged to warn about such usage in developer tools and may experiment with throwing an InvalidAccessError exception when it occurs.
未来的方向是只允许工作线程中的xmlhttprequest。这条消息意在发出这方面的警告。
其他回答
在MVC应用程序中,我得到了这个警告,因为我用一个返回View()而不是PartialView()的方法打开了一个Kendo窗口。View()试图再次检索页面的所有脚本。
在Chrome浏览器中,按“F12” 开发工具->按F1。 参见设置->通用->外观:“不显示chrome数据保护警告”-设置此复选框。 参见设置->general->Console:“Log XMLHTTPRequest”-设置此复选框。
享受
为避免此警告,请不要使用:
async: false
在任何$.ajax()调用中。这是XMLHttpRequest唯一被弃用的特性。
默认为
async: true
jQuery已经弃用了同步XMLHTTPRequest
警告消息可能是由于主线程中的XMLHttpRequest请求将async标志设置为false。
https://xhr.spec.whatwg.org/ synchronous:
Synchronous XMLHttpRequest outside of workers is in the process of being removed from the web platform as it has detrimental effects to the end user's experience. (This is a long process that takes many years.) Developers must not pass false for the async argument when the JavaScript global environment is a document environment. User agents are strongly encouraged to warn about such usage in developer tools and may experiment with throwing an InvalidAccessError exception when it occurs.
未来的方向是只允许工作线程中的xmlhttprequest。这条消息意在发出这方面的警告。
我一直在看答案,都令人印象深刻。我认为他应该提供给他一个问题的代码。给出下面的例子,如果你在page.php中有一个链接到jquery的脚本,你就会得到通知。
$().ready(function () {
$.ajax({url: "page.php",
type: 'GET',
success: function (result) {
$("#page").html(result);
}});
});