kazu Posted May 1, 2008 Share Posted May 1, 2008 Why won't this work? I know its a basic AJAX whatsit... but it refuses to work. Both IE and MF don't report any js errors... but yea... Thanks in advance. Jayden ps: i suppose some code would help m.php timerID = setInterval("chatRefresh('m.php')", 10000); function chatRefresh(url){ if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = function() {ajaxDone();}; req.open("GET", url, true); req.send(null); // IE/Windows ActiveX version } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLDOM"); if (req) { req.onreadystatechange = function() {ajaxDone();}; req.open("GET", url, true); req.send(null); } } } function ajaxDone() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { // is gonna do nothing } else { document.innerHTML="AJAX Error. Press Ctrl+R to refresh the page and pray it works =]"; } } } Quote Link to comment Share on other sites More sharing options...
markjoe Posted May 1, 2008 Share Posted May 1, 2008 req.onreadystatechange = function() {ajaxDone();}; should be: req.onreadystatechange = ajaxDone; Does document have an innerHTML property? Here's a quick and dirty that seems to work. <script type='text/javascript'> timerID = setInterval("chatRefresh('m.php')", 2000); function ajaxDone() { if (req.readyState == 4 && req.responseText) { document.getElementById('TA').innerHTML=req.responseText; } } function chatRefresh(url){ var RN=Math.round(Math.random()*1000); if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = ajaxDone; req.open("GET", url+'?rn='+RN); req.send(null); // IE/Windows ActiveX version } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLDOM"); if (req) { req.onreadystatechange = ajaxDone; req.open("GET", url); req.send(null); } } } </script> <textarea id='TA'></textarea> I didn't really bother with the IE part, testing on Firefox. This is not at all how I would do this, but it works and is closest to your original code. Oh, yea... that random number thing is the best way I've seen to prevent caching. Quote Link to comment 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.