Internet Explorer错误消息“操作超时”

问题描述:

我有一段代码在Chrome和Firefox中工作,但不在Internet Explorer中。我无法弄清楚究竟是什么原因。我收到了来自Internet Explorer的操作超时消息"Message: The operation was timed out."Internet Explorer错误消息“操作超时”

这是我使用的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作为请求是同步的。

+0

是的我知道我需要一个同步请求。如果我将其更改为“true”,那么它就是alert的“Finished”,但不会转到“页面(confirmPage.php)”。显然,它不提供错误,因为它没有等待响应。 – theking963

+0

好的,对不起。代码已更新。 – jabclab

+0

它进入'完成'但没有错误信息或输出。 – theking963

部分回答:

我想通了这个问题。这不是JavaScript和/或Ajax。 IE无法在查询中处理大量结果,因此超时。这是一个非常晦涩的错误,因为我认为这与AJAX函数有关,而不是PHP文件。

结果集不是很大。有5个不同的查询。每一个有大约5-50K记录(我不打印所有这些记录,只是查询)。它在一个大的结果集之后超时。

为了测试我创建了一个简单的SELECT *查询测试页,它只能处理2-3个查询。如果它超过它超时。