eeuser Posted May 21, 2007 Share Posted May 21, 2007 Hi ! I am very new to AJAX. Can anyone give me an example or links or show me step by step, How to automatically refresh a result from database without refreshing the page using Ajax. Example : Similiar to Yahoo stock updates http://finance.yahoo.com/q?s=yhoo Thanks In Advance Newbee Quote Link to comment Share on other sites More sharing options...
minuteman Posted May 25, 2007 Share Posted May 25, 2007 Hi, I am really new at ajax myself but maybe I can help. I just got something similar going. On mine, the script checks for a change in the db. When there is, it loads a different page. Is that what you had in mind? I'm assuming you are accessing your own db? I used what I think is basic ajax off a website somewhere that check the page every every ten seconds (see this line setInterval('sndReq()', 100000) Then, what I believe it does, is it goes to ajax.php which is just a regular php page that queries the db and if the db has changed then it will reload. That is done by "requiring" different pages depending on the db value I posted above a problem I am having with it though. I experimented with iframes and if the displayed page has any animated fetures it causes the entire page to refresh here is the code I use <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', 'ajax.php'); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4) { var response = http.responseText; document.getElementById('foo').innerHTML = response; } } setInterval('sndReq()', 100000); </script> <title>Internet Video Radio (INVIDRA)</title> </head> <body bgcolor="#FFFFF0"> <div id="foo"> retrieving data...'; </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.