JavaScript的执行console.log导致错误:"在主线程同步XMLHtt prequest是德precated ..." [英] Javascript console.log causes error: "Synchronous XMLHttpRequest on the main thread is deprecated..."

查看:194
本文介绍了JavaScript的执行console.log导致错误:"在主线程同步XMLHtt prequest是德precated ..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经添加日志到控制台检查不同变量的状态,而无需使用Firefox的调试器。

I have been adding logs to the console to check the status of different variables without using the Firefox debugger.

不过,在很多地方我在 main.js 文件中添加的console.log ,我收到以下错误,而不是我的可爱的小手写的消息对自己说:

However, in many places in which I add a console.log in my main.js file, I receive the following error instead of my lovely little handwritten messages to myself:

在主线程同步XMLHtt prequest是因为其不利影响到最终用户的体验pcated德$ P $。如需更多帮助 http://xhr.spec.whatwg.org/

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/

什么替代品或包装为的console.log 我可以添加到我的code使用不会导致这个错误?

What alternatives to or wrappers for console.log can I add to my code use that will not cause this error?

我是否做错了?

推荐答案

这发生在我身上时,我是懒惰,其中包括一个脚本标记,正在返回的内容的一部分。因此:

This happened to me when I was being lazy and included a script tag as part of the content that was being returned. As such:

部分HTML内容:

<div> 
 SOME CONTENT HERE
</div>
<script src="/scripts/script.js"></script> 

它的出现,至少在我的情况下,如果返回通过XHR HTML内容那样,你将导致jQuery来拨打电话,以获取该脚本。这调用发生与异步标志false,因为它假设你需要的脚本继续加载。

It appears, at least in my case, that if you return HTML content like that via xhr, you will cause jQuery to make a call to get that script. That call happens with an async flag false since it assumes you need the script to continue loading.

在像这样的你会通过寻找到某种形式的有约束力的框架,只是返回一个JSON对象,或根据您的后端和模板,你可以改变你的加载脚本得到更好的服务情况。

In situations like this one you'd be better served by looking into a binding framework of some kind and just returning a JSON object, or depending on your backend and templating you could change how you load your scripts.

您也可以使用 jQuery的 getScript加入() 来抢相关的脚本。这里是一个小提琴,这是jQuery的例子只是一个单纯的拷贝,但我没有看到剧本时加载这样的警告异常。

You could also use jQuery's getScript() to grab relevant scripts. Here is a fiddle, It's just a straight copy of the jQuery example, but I'm not seeing any warnings thrown when scripts are loaded that way.

http://jsfiddle.net/49tkL0qd/

这篇关于JavaScript的执行console.log导致错误:&QUOT;在主线程同步XMLHtt prequest是德precated ...&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆