markvaughn2006 Posted September 18, 2009 Share Posted September 18, 2009 I'm making a PHP/MySQL game where you can travel to different locations and there is PHP code that tells you who else is in the room with you but the problem is that if someone else enters the room you can not see them unless you refresh the page. Is there any way to use AJAX to constantly refresh only this small part of the page with the PHP code that is telling you who is there with you?? Thanks for any help!!! Quote Link to comment https://forums.phpfreaks.com/topic/174675-solved-using-ajax-to-refresh-one-small-part-of-php-page/ Share on other sites More sharing options...
RichardRotterdam Posted September 18, 2009 Share Posted September 18, 2009 You could create a javascript function that you run periodically by using setTimeout Here is a simple example without the ajax part: <script> // function for reloading the viewport div (use this function for making an ajax request) function reloadContent(){ var randomnumber = Math.floor(Math.random()*100); document.getElementById('viewport').innerHTML = "random number = "+randomnumber; // execute this function for every second setTimeout('reloadContent()', 1000); } window.onload = function(){ reloadContent(); } </script> <div id="viewport">loading</div> You also might also want to look into "Comet ajax" Quote Link to comment https://forums.phpfreaks.com/topic/174675-solved-using-ajax-to-refresh-one-small-part-of-php-page/#findComment-920681 Share on other sites More sharing options...
markvaughn2006 Posted September 19, 2009 Author Share Posted September 19, 2009 cool thanks!! after asking that question I realized how vague and noob it was, thanks for not being an a$$, lol Quote Link to comment https://forums.phpfreaks.com/topic/174675-solved-using-ajax-to-refresh-one-small-part-of-php-page/#findComment-921011 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.