javascript 主线程上的同步 XMLHttpRequest 已弃用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29481767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Synchronous XMLHttpRequest on the main thread is deprecated
提问by
- I am working on extjs framework..
- i have an application running on extjs..
- whenever i open the application in the browser...i see the following warnings in my console...
- 我正在研究 extjs 框架..
- 我有一个在 extjs 上运行的应用程序。
- 每当我在浏览器中打开应用程序时...我在控制台中看到以下警告...
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/
主线程上的同步 XMLHttpRequest 已被弃用,因为它会对最终用户的体验产生不利影响。如需更多帮助,请查看http://xhr.spec.whatwg.org/
- can you guys tell me how to remove it..
- when i click the warning it takes to ext-all-debug-w-comments.js file
and points to the following part of code...
try { xhr.open('GET', noCacheUrl, false); xhr.send(null); } catch (e) { isCrossOriginRestricted = true; }
can you guys tell me how to prevent it from happening...
providing my code below in that file
/** * Load a script file, supports both asynchronous and synchronous approaches * @private */ loadScriptFile: function(url, onLoad, onError, scope, synchronous) { if (isFileLoaded[url]) { return Loader; }
var config = Loader.getConfig(), noCacheUrl = url + (config.disableCaching ? ('?' + config.disableCachingParam + '=' + Ext.Date.now()) : ''), isCrossOriginRestricted = false, xhr, status, onScriptError, debugSourceURL = ""; scope = scope || Loader; Loader.isLoading = true; if (!synchronous) { onScriptError = function() { }; scriptElements[url] = Loader.injectScriptElement(noCacheUrl, onLoad, onScriptError, scope); } else { if (typeof XMLHttpRequest != 'undefined') { xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } try { xhr.open('GET', noCacheUrl, false); xhr.send(null); } catch (e) { isCrossOriginRestricted = true; } status = (xhr.status === 1223) ? 204 : (xhr.status === 0 && (self.location || {}).protocol == 'file:') ? 200 : xhr.status; isCrossOriginRestricted = isCrossOriginRestricted || (status === 0); if (isCrossOriginRestricted ) { } else if ((status >= 200 && status < 300) || (status === 304) ) { // Debugger friendly, file names are still shown even though they're eval'ed code // Breakpoints work on both Firebug and Chrome's Web Inspector if (!Ext.isIE) { debugSourceURL = "\n//@ sourceURL=" + url; } Ext.globalEval(xhr.responseText + debugSourceURL); onLoad.call(scope); } else { } // Prevent potential IE memory leak xhr = null; } },
- 大佬能告诉我怎么去掉吗
- 当我单击 ext-all-debug-w-comments.js 文件的警告时
并指向以下代码部分...
尝试 { xhr.open('GET', noCacheUrl, false); xhr.send(null); } catch (e) { isCrossOriginRestricted = true; }
你们能告诉我如何防止它发生吗...
在该文件中提供我的代码
/** * 加载脚本文件,支持异步和同步两种方式 * @private */ loadScriptFile: function(url, onLoad, onError, scope, synchronous) { if (isFileLoaded[url]) { return Loader; } }
var config = Loader.getConfig(), noCacheUrl = url + (config.disableCaching ? ('?' + config.disableCachingParam + '=' + Ext.Date.now()) : ''), isCrossOriginRestricted = false, xhr, status, onScriptError, debugSourceURL = ""; scope = scope || Loader; Loader.isLoading = true; if (!synchronous) { onScriptError = function() { }; scriptElements[url] = Loader.injectScriptElement(noCacheUrl, onLoad, onScriptError, scope); } else { if (typeof XMLHttpRequest != 'undefined') { xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } try { xhr.open('GET', noCacheUrl, false); xhr.send(null); } catch (e) { isCrossOriginRestricted = true; } status = (xhr.status === 1223) ? 204 : (xhr.status === 0 && (self.location || {}).protocol == 'file:') ? 200 : xhr.status; isCrossOriginRestricted = isCrossOriginRestricted || (status === 0); if (isCrossOriginRestricted ) { } else if ((status >= 200 && status < 300) || (status === 304) ) { // Debugger friendly, file names are still shown even though they're eval'ed code // Breakpoints work on both Firebug and Chrome's Web Inspector if (!Ext.isIE) { debugSourceURL = "\n//@ sourceURL=" + url; } Ext.globalEval(xhr.responseText + debugSourceURL); onLoad.call(scope); } else { } // Prevent potential IE memory leak xhr = null; } },
采纳答案by Lorenz Meyer
This warning is only showing in Chrome in the development environment of ExtJs. Once the application is built with sencha cmd
, the warning doesn't show anymore. As @Evan pointed out the warning looks benign, and you should not have to worry about it.
此警告仅在 ExtJs 开发环境中的 Chrome 中显示。使用 构建应用程序后sencha cmd
,警告不再显示。正如@Evan 指出的那样,警告看起来是良性的,您不必担心。
The fact that there is a warning should not be an issue, since it will never show in a deployed application. If you do not yet use sencha cmd, it is definitely worth to integrate it in your development cycle.
存在警告这一事实不应成为问题,因为它永远不会显示在已部署的应用程序中。如果您还没有使用 sencha cmd,那么将它集成到您的开发周期中绝对值得。
I know it is not a direct answer to the question. Myself, I wonder if it is possible to get rid of this warning at all.
我知道这不是问题的直接答案。我自己,我想知道是否有可能完全摆脱这个警告。