javascript IE 中“启用原生 XMLHTTP 支持”选项的目的是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10347963/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 09:33:50  来源:igfitidea点击:

What is the purpose of "Enable native XMLHTTP support" option in IE

javascriptajaxinternet-explorermemory-leaksxmlhttprequest

提问by Al.

Our website uses AJAX call and uses XMLHTTPRequestto acheive that. When client uses an single IE instance through out the day and countinously navigating and refesing the page with in that IE, we end up with out of memory exception and forced to close the IE.

我们的网站使用 AJAX 调用并用于XMLHTTPRequest实现这一点。当客户端全天使用单个 IE 实例并在该 IE 中多次导航和引用页面时,我们最终会出现内存不足异常并被迫关闭 IE。

By enabling the option Enable native XMLHTTP supportin Advnaced tab of IE fixes the issue. Since we prefers native XMLHTTP object over ActiveXObject, the exception might be caused due to using ActiveXObject. But still not sure what could be the root cause or is there any other better way to solve the issue. We use IE8. We have never encounterd any such issue in other browsers(Firefox and chrome). Thanks

通过启用Enable native XMLHTTP supportIE 的 Advnaced 选项卡中的选项可修复该问题。由于我们更喜欢原生 XMLHTTP 对象而不是 ActiveXObject,因此异常可能是由于使用 ActiveXObject 引起的。但仍然不确定可能是根本原因,或者有没有其他更好的方法来解决这个问题。我们使用IE8。我们在其他浏览器(Firefox 和 chrome)中从未遇到过此类问题。谢谢

回答by Peter Aron Zentai

Enable native XMLHTTP support means that the browser will not provide MSXML.HttpRequest but instead window.XMLHttpRequest that is standards compliant. We successfully used however both versions without any leakage whatsoever, so I guess it must be some implementation issue in your code - I am just guessing, but pinning MSXML.HttpRequest instances on DOMNodes (via an eventlistener) can lead to such situations.

启用原生 XMLHTTP 支持意味着浏览器将不提供 MSXML.HttpRequest,而是提供符合标准的 window.XMLHttpRequest。然而,我们成功地使用了两个版本而没有任何泄漏,所以我想这一定是您的代码中的一些实现问题 - 我只是猜测,但是将 MSXML.HttpRequest 实例固定在 DOMNodes 上(通过事件侦听器)会导致这种情况。

回答by Oleg V. Volkov

"Enable native XMLHTTP support” option in IE, unsurprisingly, makes IE provide native support for XMLHTTPRequest. If you don't enable this, you'll only have legacy ActiveX binding to MSXML library in IE. I guess you use some library that provides cross-browser handling for cases where native support is absent (setting turned off or older IE that only have legacy interface) or manually fallback to MSXML. Since MSXML binding is an alien interface for JavaScript, there are many places where objects introduced from outside JS can form cross-references with native objects, not letting either JS or ActiveX garbage collector to reclaim them, since they don't communicate and can't find such circular references.

“启用原生 XMLHTTP 支持”在 IE 中的选项,不出所料,使 IE 提供对 XMLHTTPRequest 的原生支持。如果你不启用这个,你将只有传统的 ActiveX 绑定到 IE 中的 MSXML 库。我猜你使用了一些提供跨浏览器处理缺少本机支持的情况(设置关闭或只有旧版界面的旧版 IE)或手动回退到 MSXML。由于 MSXML 绑定是 JavaScript 的外来界面,因此有很多地方是从 JS 外部引入的对象可以与本机对象形成交叉引用,不让 JS 或 ActiveX 垃圾收集器回收它们,因为它们不通信并且找不到这样的循环引用。

Best solution, in my opinion, is to recommend IE7 users to always have this option on (there's really zero drawbacks to it) and just forget about older browsers. If this is not an option somehow, try recursively clear all MSXML objects you create in your fallback code.

在我看来,最好的解决方案是建议 IE7 用户始终启用此选项(它的缺点确实为零)并且忘记旧浏览器。如果这不是一个选项,请尝试递归清除您在回退代码中创建的所有 MSXML 对象。

回答by Ben

Essentially you are leaking XMLHTTPRequest objects, due to circular refrerences between the HTML DOM, the JavaScript execution engine, and the XMLHTTPRequest object.

本质上,由于 HTML DOM、JavaScript 执行引擎和 XMLHTTPRequest 对象之间的循环引用,您正在泄漏 XMLHTTPRequest 对象。

You need to unhook the events and dereference the XMLHttp objects when the request completes. (To dereference them make sure no JavaScript object or variable references them, including the little bits of script in the onClick handlers etc.

当请求完成时,您需要取消挂接事件并取消对 XMLHttp 对象的引用。(要取消引用它们,请确保没有 JavaScript 对象或变量引用它们,包括 onClick 处理程序中的少量脚本等。

Enabling native XMLHTTPRequest means that the external component is taken out of the loop, so the DOM is able to manage the request lifetime itself.

启用原生 XMLHTTPRequest 意味着将外部组件从循环中取出,因此 DOM 能够自己管理请求生命周期。

See also @PeterAronZentai's answer.

另请参阅@PeterAronZentai 的回答。