简体   繁体   English

JavaScript-IE中的XMLHttpRequest overlayMimeType

[英]JavaScript - XMLHttpRequest overrideMimeType in IE

Take this code: 采取以下代码:

let jsonRequest = new XMLHttpRequest();
jsonRequest.overrideMimeType("application/json");
jsonRequest.open('GET', './js/settings.json', true);

IE doesn't support overrideMimeType , and my HTML has been set to UTF-8 . IE不支持overrideMimeType ,并且我的HTML已设置为UTF-8 Is there a risk to leaving the overrideMimeType line out? overrideMimeType行留在外面会有风险吗? It seems to work fine without it. 没有它似乎工作正常。 This question has pretty much the same issue, but the answer isn't really clear. 这个问题几乎是相同的问题,但是答案还不清楚。

IE started supporting this mime-type overriding from their v11. IE从他们的v11开始支持这种MIME类型的覆盖。 But this is never necessary in practice, which is discussed on the other post you've linked. 但这实际上是没有必要的,您链接的另一篇文章对此进行了讨论。

From the security point, that you are concerned about - the answer is NO. 从安全角度考虑,您担心的是-答案是否定的。 Not using this can't impose any security issue, similarly using this alone won't make you better secure. 不使用此功能不会带来任何安全问题,类似地,仅使用此功能也无法提高安全性。

If you're concerned about response validity, say for example - if it's valid json before parsing and using, there is a better choice of using getResponseHeader method, which will also facilitate you aborting the request in case of invalid header very early as soon as the headers arrived; 如果您担心响应的有效性,例如-如果在解析和使用之前它是有效的json,则可以使用getResponseHeader方法更好的选择,这也将有助于您在报头无效的情况下尽快中止请求。标头到达; see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getResponseHeader 参见https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getResponseHeader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM