IE 9 Javascript 错误 c00c023f
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7287706/
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
IE 9 Javascript error c00c023f
提问by peipei
I came across this error only on IE9:
我只在 IE9 上遇到过这个错误:
SCRIPT575: Could not complete the operation due to error c00c023f.
SCRIPT575:由于错误 c00c023f,无法完成操作。
The error happened on this line: if ((a.responseXML) && (a.readyState==4)) {
错误发生在这一行: if ((a.responseXML) && (a.readyState==4)) {
I cant figure it out why this happened, and it seems to work very well in other browsers.
我无法弄清楚为什么会发生这种情况,并且它似乎在其他浏览器中运行良好。
and this is my javascript code:
这是我的 javascript 代码:
var a = new XMLHttpRequest();
a.open("GET",'/cust/ajax/getresult.php?qk=nnf87&arg1='+pzid,true);
a.onreadystatechange = function () {
if ((a.responseXML) && (a.readyState==4)) {
var N = a.responseXML.getElementsByTagName('result')
sequence = N[0].firstChild.data;
var SEQ = sequence.split(",");
var num = SEQ.length;
var sum = 0;
for(var n=0;n<num;n++){sum = sum + (SEQ[n]*1);}
//document.getElementById("the_number_of").innerHTML = sum;
var date = new Date();
date.setTime(date.getTime()+(2*60*60*1000));
document.cookie='cpa_num='+sum+'; expires= '+date.toGMTString()+'; path=/';
}
}
回答by Matt
I don't suppose your request is being aborted? A quick Googling found thisblog post. It would seem that an aborted request in IE9 will give this error when trying to read any properties off of the XMLHttpRequest object.
我不认为你的请求被中止了?快速谷歌搜索找到了这篇博文。当尝试从 XMLHttpRequest 对象读取任何属性时,IE9 中的中止请求似乎会出现此错误。
From the post, their particular problem with this error code could be duplicated by:
从帖子中,他们与此错误代码的特定问题可能会通过以下方式重复:
- Create a XMLHttpRequest object
- Assign an onreadystatechanged event handler
- Execute a request
- Abort the request before the response has been handled
- 创建一个 XMLHttpRequest 对象
- 分配一个 onreadystatechanged 事件处理程序
- 执行请求
- 在响应被处理之前中止请求
You will now see that the readystatechange handler will be called, with the readystate property set to '4'. Any attempt to read the XmlHttpRequest object properties will fail.
您现在将看到将调用 readystatechange 处理程序,并将 readystate 属性设置为“4”。任何读取 XmlHttpRequest 对象属性的尝试都将失败。
The author mitigates this problem by assigning an abort state to the request when the manual-abort is performed, and detecting it and returning before trying to read any other properties. Though this approach would only really work if you are performing the abort yourself.
作者通过在执行手动中止时为请求分配中止状态来缓解这个问题,并在尝试读取任何其他属性之前检测它并返回。尽管这种方法只有在您自己执行中止时才真正有效。
A similar problem was documented on the this WebSync Google Groups post. Towards the end of the discussion there is an implication that this problem only occurs
此 WebSync Google Groups 帖子中记录了类似的问题。在讨论结束时,暗示这个问题只会发生
if you've got the standards and IE9 rendering modes both set
如果您同时设置了标准和 IE9 渲染模式
Hope that points you in the right direction.
希望这为您指明了正确的方向。
回答by Ran Cohen
Switch the
切换
if ((a.responseXML) && (a.readyState==4))
to
到
if ((a.readyState==4) && (a.responseXML))
As the order matters. it seems that on IE9 if the state is not 4, the responseXML and reponseText yield this error if being accessed (I have no clue why...)
因为顺序很重要。似乎在 IE9 上,如果状态不是 4,则 responseXML 和 reponseText 如果被访问会产生此错误(我不知道为什么......)
回答by glenn
Within the readyState==4 routine, include a try and catch similar to:
在 readyState==4 例程中,包含类似于以下内容的 try 和 catch:
try {
var response=xmlHttp.responseText;
}
catch(e) {
var response="Aborted";
}
We found that this to be the most successful resolution to the above.
我们发现这是对上述问题最成功的解决方案。
回答by Jim
I was getting this error in my Framework. It only shows up in IE (go figure). I simply wrapped the response like below:
我在我的框架中收到此错误。它只出现在 IE 中(去图)。我只是简单地将响应包装如下:
if(request.readyState == 4)
{
// get response
var response = request.responseText;
}
回答by Pete Alvin
It happens for me with IE9 when I read the "status" property prematurely (before readyState is 4 / DONE).
当我过早地读取“状态”属性(在 readyState 为 4 / DONE 之前)时,IE9 会发生这种情况。