【发布时间】:2012-01-18 14:27:33
【问题描述】:
我有一段代码可以在 chrome 和 firefox 中运行,但不能在 Internet Explorer 中运行。我无法弄清楚那个真正的原因是什么。我从 Internet Explorer 收到操作超时消息"Message: The operation was timed out."
这是我正在使用的 ajax 函数,它来自 w3schools,所以我知道这是正确的。
function ajax() {
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
alert(xmlhttp);
return xmlhttp;
}
这是卡住的代码。错误信息在"ajaxRequest.send(postdata);"。
function edit(){
var ajaxRequest = ajax();
var postdata = "data=" + document.getElementById("id1").value + "<|>" + document.getElementById("id2").value + "<|>" + document.getElementById("id3").value;
ajaxRequest.onreadystatechange = function(){
var ajaxDisplay = document.getElementById('ajaxDiv');
if(ajaxRequest.readyState == 4 && ajaxRequest.status==200){
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
alert(postdata);
ajaxRequest.open("POST","confirmPage.php",false);
ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajaxRequest.send(postdata);
alert("Finished");
}
所有其他页面在 Internet Explorer 中使用相同的代码,但不是这个特定页面。我似乎无法弄清楚为什么。此页面适用于 chrome 和 firefox,但不适用于 Internet Explorer。它永远不会“完成”。我正在使用 IE 8。
【问题讨论】:
标签: javascript ajax internet-explorer timeout