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 =]"; } } } Link to comment https://forums.phpfreaks.com/topic/103673-need-some-real-basic-help-plz/ 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. Link to comment https://forums.phpfreaks.com/topic/103673-need-some-real-basic-help-plz/#findComment-530851 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.