aarontan78 Posted May 6, 2008 Share Posted May 6, 2008 Hi all AJAX gurus Althought there are a lot of tutorials on retrieving data using ajax, I cant find any tutorial on how to display UPDATED records AUTOMATICALLY from mysql without having user to do onclick. Can someone enlighten me? Thanks Quote Link to comment Share on other sites More sharing options...
aarontan78 Posted May 7, 2008 Author Share Posted May 7, 2008 I have found the below code and modify a bit..somehow, it didn display the updated records. Can someone knows what the problem with below coding? connect.inc is the database connection and the page itself is saved as 'test.php' Thanks. <html> <head> <script type="text/javascript"> function createRequestObject() { var ro; var browser = navigator.appName; if(browser == 'Microsoft Internet Explorer') { ro = new ActiveXObject("Microsoft.XMLHTTP"); } else { ro = new XMLHttpRequest(); } return ro; } var http = createRequestObject(); function sndReq(action) { http.open('get', 'test.php'); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4) { var response = http.responseText; document.getElementById('foo').innerHTML = response; } } setInterval('sndReq()', 1); </script> </head> <body> <div id="foo"> <?php include("inc/connect.inc"); $q1 = "SELECT EVENT_DESC FROM EVENTS"; $r1 = mysql_query($q1); $EVENT_DESC = mysql_result($r1,0,0); echo $EVENT_DESC; ?> </div> </body> </html> 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.