...

View Full Version : Refreshing <div> content



Apocalypse
02-26-2011, 05:11 AM
For the last year and a half, I have been developing an online text and image-based game in PHP, SQL, HTML, CSS, Java, etc. I need help creating a script that will reload one string (from an SQL database) every five seconds or so without reloading the rest of the page. I have been looking for help all over the internet and since none of the threads posted that I have found on the subject correspond to my specifications, I am posting a thread myself. So far I have collected that I can use Ajax to reload <div> content. I need to refresh part of the PHP page (an SQL database value), which can be contained between <div> tags, automatically every five seconds without reloading the rest of the page. Can I get some help?

bullant
02-26-2011, 05:20 AM
You can use setInterval() to send an ajax request every 5 seconds to the server to get the string from the database. When the string is returned to the ajax function, it can then set the returned string to the contents of a div.

Apocalypse
02-26-2011, 06:11 PM
I'm not very familiar with Ajax, and I'm not amazing with Java either. Can I get an example?

harbingerOTV
02-26-2011, 06:28 PM
http://roshanbh.com.np/2008/03/call-php-ajax-every-second-jquery.html

you'd want to replace: 'ajaxTime.php?randval='+ Math.random()

with your pages name. On that page you'd place your call to you SQL script.

And, for reference, the jQuery load function: http://api.jquery.com/load/

bullant
02-26-2011, 07:59 PM
I'm not very familiar with Ajax, and I'm not amazing with Java either. Can I get an example?

AJAX tutorial (http://www.w3schools.com/Ajax/ajax_intro.asp)

Apocalypse
02-27-2011, 11:33 PM
http://roshanbh.com.np/2008/03/call-php-ajax-every-second-jquery.html

you'd want to replace: 'ajaxTime.php?randval='+ Math.random()

with your pages name. On that page you'd place your call to you SQL script.

And, for reference, the jQuery load function: http://api.jquery.com/load/

Perfect, thanks man.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum