problem whit setInterval and IE
Hi,
with Mozila everything work, but with IE didn't work. Page didn't reload.
What's wrong?
<html>
<head>
<script type="text/javascript">
setInterval("sendRequest()", 1000*2);
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
// IE 7, Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 6, 5
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert('Problem creating the XMLHttpRequest object');
}
return req;
}
var http = createRequestObject();
function sendRequest() {
http.open('GET', 'select.php', true);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response)
{
document.getElementById('text').innerHTML = response;
}
}
}
</script>
</head>
<body>
<div id="text"></div>
</body>
</html>
Lolalola
Junior Poster in Training
76 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
Lolalola,
As far as I can tell, an IE XMLHTTP request is a one-shot affair whereas in Moz it will work many times over.
As such, there is little point in making your "http" global. It can (and should I believe) be declared within sendRequest() with var http = createRequestObject(); .
You will then need to change the way that handleResponse is called (attach an anonymous function which calls handleResponse with http.responseText as its argument). It is also advisable to attach this listener before http.open, not after.
This is a pretty standard pattern, of which you should find many examples here on Daniweb and elsewhere.
Hope this helps.Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372