我一直在向控制台添加日志,以检查不同变量的状态,而不使用Firefox调试器。

然而,在我在main.js文件中添加console.log的许多地方,我收到了以下错误,而不是我给自己的可爱的手写消息:

主线程上的同步XMLHttpRequest已弃用,因为它会对最终用户的体验产生不利影响。更多帮助http://xhr.spec.whatwg.org/

我可以在我的代码使用中添加哪些不会导致此错误的console.log替代品或包装器?

我“做错了”吗?


当前回答

我用以下步骤来解决这个问题:

检查您的CDN脚本并在本地添加它们。 将脚本包含移动到标题部分。

其他回答

警告消息可能是由于主线程中的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);
   }});
 });

在我的情况下,这是由Cloudflare提供的“CDNJS选择”应用程序中的灵活脚本引起的。

根据Cloudflare的说法,“该应用程序已于2015年3月弃用”。我把手机关掉,留言立刻就消失了。

您可以通过访问https://www.cloudflare.com/a/cloudflare-apps/yourdomain.com访问这些应用程序

注意:这是我在这个线程上的答案的副本同步XMLHttpRequest警告和<脚本>(我在寻找解决方案时访问了这两个)

我得到了这个例外,包括一个can.js脚本在另一个,例如,

{{>anotherScript}}

像@Nycen一样,我也得到了这个错误,因为一个链接到Cloudfare。我的是Select2插件。

我刚把它拆了

 src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"

错误消失了。