tomfmason Posted November 4, 2006 Share Posted November 4, 2006 I have a simple function that gets the time from a php script.. I have the timeout set to 500 so that it will give it the appearance of a clock.. Well this works fine in FF and Opera.But in IE it will only work if I don't set a time out. In which case it will not reload the time.. Here is the function in question..[code]function sendRequest() { http.open('GET', 'process.php?action=getTime'); http.send(null); http.onreadystatechange = handleRequest;}function handleRequest() { if (http.readyState == 4) { clearInterval(dtimer); var response = http.responseText; document.getElementById('time').innerHTML = response; var browser = navigator.appName; if (browser == 'Microsoft Internet Explorer') { dtimer = setTimeout('sendRequest();', 500); }else{ dtimer = setTimeout('sendRequest();', 500); } }}[/code]here is a live link.. http://www.thomashostings.net/home/layout/layout2/ The part in question is in the upper right hand corner. Any suggestions would be great.Thanks,Tom Quote Link to comment https://forums.phpfreaks.com/topic/26116-issue-with-settimeout-and-ie/ Share on other sites More sharing options...
ober Posted November 4, 2006 Share Posted November 4, 2006 I'm not sure why you're using the colon after the function call, but maybe this example that I wrote will help:index.php[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title>ajax example</title> <scri pt type="text/javascript" src="update.js"></s cript></head><body style="text-align:center;"> <div id="dump"> STUFF <!-- ajax --> </div> <input type="button" name="start" id="start" value="Start Update" onclick="update();" /></body></html>[/code]backend.php:[code]<?phpecho date("n/j/Y h:i:s A");?>[/code]update.js:[code]function createRequestObject(){ if (window.XMLHttpRequest) { // Mozilla, Safari, Opera... var xmlhttp = new XMLHttpRequest(); if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml'); } else if (window.ActiveXObject) { // IE try { var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!xmlhttp) { alert('Giving up. Cannot create an XMLHTTP instance'); return false; } return xmlhttp;}/* You can get more specific with version information by using parseInt(navigator.appVersion) Which will extract an integer value containing the version of the browser being used. The variable http will hold our new XMLHttpRequest object. */var http = createRequestObject(); function update(){ http.abort(); http.open('post', 'backend.php'); http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); http.send('act=1'); http.onreadystatechange = handleDump; setTimeout("update()",1000);}function handleDump(){ if(http.readyState == 4) //Finished loading the response { var response = http.responseText; document.getElementById('dump').innerHTML = response; }}[/code]Works in IE, FF, Opera. Quote Link to comment https://forums.phpfreaks.com/topic/26116-issue-with-settimeout-and-ie/#findComment-119445 Share on other sites More sharing options...
ober Posted November 4, 2006 Share Posted November 4, 2006 www.whproductions.com/phpfreaks/time is where a live example is. Quote Link to comment https://forums.phpfreaks.com/topic/26116-issue-with-settimeout-and-ie/#findComment-119449 Share on other sites More sharing options...
tomfmason Posted November 4, 2006 Author Share Posted November 4, 2006 Thanks ober..Once again you have been a great help... [img]http://www.thomashostings.net/images/smiles.gif[/img]Thanks again,Tom Quote Link to comment https://forums.phpfreaks.com/topic/26116-issue-with-settimeout-and-ie/#findComment-119679 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.