ajax triggers,AJAX triggers ReadyState 4 several times in IE

I am experiencing a strange problem where IE8 will fire readyState 4 three or four times on an ajax request. This happens often but not always, and only for a couple of specific links - the rest of my ajax links are fine. My object creation and onreadystatechange handler are basic, ie.

function ajaxPost(params) {

try {

// Firefox, Opera 8.0+, Safari

xmlHttp = new XMLHttpRequest();

} catch (e) {

// Internet Explorer

try {

xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try {

xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

} catch (e) {

alert('Unsupported Browser');

}

}

}

xmlHttp.onreadystatechange = function() {

if (xmlHttp.readyState == 4) {

// Do something

}

}

xmlHttp.open("POST", path_to_script);

xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

xmlHttp.setRequestHeader("Cache-Control", "must-revalidate");

xmlHttp.send(params);

}

Not sure if this is relevant - but at the points where the problem happens the user has already been navigating an ajax UI. They have clicked several other ajax links without reloading the page - each link uses a new xmlHttpRequest object with the same global variable name (xmlHttp), but each ajax request finishes before another can be issued. Do I need to do any "cleanup" or something for IE8? This has never happened using Safari, Firefox, Chrome, or any other browser.

Any insight would be much appreciated.

Thanks, Brian

Since your xmlHttp object is global, may be IE8 assigns a new onreadystatechange each time you call ajaxPost instead of replacing it.

That may explain an erratic behavior, as it depends on the number of calls to ajaxPost.

more

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值