I have a piece of code that works in chrome and firefox but not in internet explorer. I can't figure out what that actual cause is. I get a operation timeout message from internet explorer "Message: The operation was timed out."
This is the ajax function I am using, it's from w3schools so I know this is correct.
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;
}
This is the code that's getting stuck on. The error message is in "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");
}
All the other pages work with the same code in internet explorer but not this particular page. I can't seem to figure to out why. This page works in chrome and firefox but not in internet explorer. It never goes to "Finished". I am using IE 8.
As you require synchronous behaviour try the following:
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");
You don't need the onreadystatechange
as the request is synchronous.
Partial answer:
I figured out the problem. It's not javascript and/or ajax. IE can't handle a large number of results in queries so it times out. It's a very obscure error as I was thinking it's something to do with the ajax functions rather than the php file.
The result set is not huge. There are 5 different queries. Each one with about 5-50K records(I am not printing all of them, just querying). It times out after a large result set.
To test I created a test page with simple SELECT *
queries and it can handle only 2-3 queries. If it's more than that it times out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.