【发布时间】:2015-06-11 11:17:00
【问题描述】:
- 我正在开发 extjs 框架..
- 我有一个在 extjs 上运行的应用程序..
- 每当我在浏览器中打开应用程序时...我都会看到以下内容 我的控制台中的警告...
主线程上的同步 XMLHttpRequest 已被弃用,因为它对最终用户的体验产生不利影响。如需更多帮助,请查看http://xhr.spec.whatwg.org/
- 你们能告诉我如何删除它吗..
- 当我点击 ext-all-debug-w-cmets.js 文件的警告时
-
并指向以下代码部分...
试试{ xhr.open('GET', noCacheUrl, false); xhr.send(null); } 抓住 (e) { isCrossOriginRestricted = true; }
你们能告诉我如何防止它发生吗...
-
在该文件下方提供我的代码
/** * 加载脚本文件,支持异步和同步两种方式 * @私人的 */ loadScriptFile:函数(url,onLoad,onError,范围,同步){ if (isFileLoaded[url]) { 返回装载机; }
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; } },
【问题讨论】:
-
xhr.open('GET', noCacheUrl, false);删除false。但是,您必须将try-catch语句下方的所有内容移动到事件处理程序中,例如xhr.addEventListener('load',function(){...code...})。 -
@xufox 令人困惑,您可以在下面小提琴jsfiddle.net/e1hfjue1中的代码中更新@
-
只有在使用动态加载时才会发生。这不是一个真正的问题。
-
jsfiddle.net/e1hfjue1/1 像这样的东西。我无法验证它是否真的有效,因为我没有完整的脚本。
-
@EvanTrimboli 但如何删除该警告
标签: javascript jquery html ajax extjs