ie9ajax报错,IE9 AJAX错误:“无法完成操作由于错误c00c023f”

我有运行PHP脚本的AJAX请求,我想处理的情况是请求返回状态500IE9 AJAX错误:“无法完成操作由于错误c00c023f”

我的代码是工作在Chrome和Firfox,但在IE9上,如果我添加一个条件if(httpRequest.status==500)我得到这个JavaScript错误:

Could not complete the operation due to error c00c023f。

我在页面上有一个加载图像,并且由于此错误,我无法替换图像,并且页面似乎仍在加载。正如这里引述:

Especially if you're displaying a "loading animation" or anything similar while the request is being executed. The result in my case was that it seemed as the page never stopped loading

首先,这里是我的AJAX调用代码:

function sendRequest(url, params, divToChange)

{

// code for IE7+, Firefox, Chrome, Opera, Safari

if (window.XMLHttpRequest)

{

var httpRequest = new XMLHttpRequest();

}

else // code for IE6, IE5

{

var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");

}

//open the request and prepare variables for the PHP method being activated on server side//

httpRequest.open("POST", url, true);

//Set request headers for POST command//

httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

if(divToChange != "false")

{

httpRequest.onreadystatechange=function()

{

if(httpRequest.readyState==4 && httpRequest.status==200)

{

document.getElementById(divToChange).innerHTML=httpRequest.responseText;

eval(document.getElementById("runscript").innerHTML);

}

else if (httpRequest.status==500)

{

document.getElementById(divToChange).innerHTML=httpRequest.responseText;

//eval the lang variable from the php script.

eval(document.getElementById("runscript").innerHTML);

if(lang == "en")

{

document.getElementById(divToChange).innerHTML=' An error accured, please try again later';

}

else

{

document.getElementById(divToChange).innerHTML=' שגיאה התרחשה, בבקשה נסה שנית מאוחר יותר';

}

}

}

}

httpRequest.send(params); //sending the request to the server//

}

Just before you call the XmlHttpRequest.abort() method, set a flag on it, this is how I did it:

XmlHttpRequest.aborted = true;

XmlHttpRequest.abort();

In the onreadystatechanged handler, the first lines of code in my case is:

if (xmlHttpRequest.aborted==true) {

stopLoadAnimation();

return;

}

但在我而言,我不甚至称XmlHttpRequest.abort(),所以为什么我获得第一名的错误?顺便说一句,如果我删除所有的条件else if (httpRequest.status==500)和它的所有代码,我不会得到错误,但是,然后再次,我不能够显示消息500错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值