![](/img/trans.png)
[英]“Operation aborted” error message when loading a webpage in Internet Explorer
[英]Internet Explorer error message “The operation was timed out”
我有一段代碼可以在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。
當您需要同步行為時,請嘗試以下操作:
ajaxRequest.open("POST", "confirmPage.php", false);
ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajaxRequest.send(postdata);
if (ajaxRequest.status === 200) {
document.getElementById('ajaxDiv').innerHTML = ajaxRequest.responseText;
}
alert("Finished");
您不需要onreadystatechange
因為請求是同步的。
部分答案:
我解決了這個問題。 不是javascript和/或ajax。 IE無法處理查詢中的大量結果,因此超時。 這是一個非常晦澀的錯誤,因為我一直認為這與ajax函數而不是php文件有關。
結果集不是很大。 有5個不同的查詢。 每個記錄大約有5-50K(我不打印所有記錄,只是查詢)。 在設置大量結果后超時。
為了進行測試,我使用簡單的SELECT *
查詢創建了一個測試頁,它只能處理2-3個查詢。 如果不止於此,它將超時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.