javascript IE 中的“未指定错误”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7633722/
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
What does 'unspecified error' mean in IE?
提问by ripper234
I'm getting unspecified error
when reading document.namespaces
in IE8.
我在 IE8 中unspecified error
阅读时得到了document.namespaces
。
I can't seem to reproduce the problem in a standalone page, my snippet is:
我似乎无法在独立页面中重现该问题,我的代码段是:
function addNamespace(key, value) {
try {
$("html").attr(key, value);
if (document.namespaces && // This throws the error
!document.namespaces[key]) {
document.namespaces.add(key, value);
}
} catch (e) {
alert("Error: " + e);
}
};
Never mind right now why I'm trying to add a namespace at runtime (it has to do with Facebook Like not working properly... see this comment - Facebook like button showing in Firefox but not showing in IE).
现在不要介意为什么我要在运行时添加命名空间(这与 Facebook Like 无法正常工作有关……请参阅此评论 - Facebook like 按钮显示在 Firefox 中但未显示在 IE 中)。
My question is simple - on what conditions does unspecified error
occur?
我的问题很简单 - 在什么条件下会unspecified error
发生?
回答by Zeleres
Unspecified errors seem to occur when something (usually a value) isn't set or initialized correctly that the browser is attempting to use. I've seen a lot of unspecified errors from Ajax code attempting to access something (usually from the DOM) before the page has finished loading (even if the page appears to have already loaded)...
当浏览器尝试使用的某些内容(通常是值)未正确设置或初始化时,似乎会发生未指定的错误。我已经看到 Ajax 代码尝试在页面加载完成之前访问某些内容(通常来自 DOM)时出现许多未指定的错误(即使页面似乎已经加载)...
Some Googling on this error shows some people saying this is a browser issue, but through my own experience I strongly suspect it has to do with some asynchronous code not running in the order in which you thinkit is running.
对此错误的一些谷歌搜索显示有些人说这是浏览器问题,但根据我自己的经验,我强烈怀疑这与某些异步代码没有按照您认为的运行顺序运行有关。
回答by LYu
In my opinion, this error in IE is very similar to this common one in chrome
在我看来,IE 中的这个错误与 chrome 中的这个常见错误非常相似
Uncaught SyntaxError: Unexpected token <
Uncaught SyntaxError: Unexpected token <
For those ones who encounter this while using polyfills for IE.
对于那些在为 IE 使用 polyfills 时遇到这种情况的人。
Check your order of importing different libraries, make sure the dependency relationship is correct, also if you use requireJS, this error may be caused the error from the config file as well.
检查你导入不同库的顺序,确保依赖关系是正确的,如果你使用requireJS,这个错误也可能是配置文件的错误造成的。