Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2011, 05:11 AM   PM User | #1
Apocalypse
New to the CF scene

 
Join Date: Feb 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Apocalypse is an unknown quantity at this point
Refreshing <div> content

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?
Apocalypse is offline   Reply With Quote
Old 02-26-2011, 05:20 AM   PM User | #2
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
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.
bullant is offline   Reply With Quote
Users who have thanked bullant for this post:
akosiana (02-26-2011)
Old 02-26-2011, 06:11 PM   PM User | #3
Apocalypse
New to the CF scene

 
Join Date: Feb 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Apocalypse is an unknown quantity at this point
I'm not very familiar with Ajax, and I'm not amazing with Java either. Can I get an example?
Apocalypse is offline   Reply With Quote
Old 02-26-2011, 06:28 PM   PM User | #4
harbingerOTV
Senior Coder

 
Join Date: Jan 2005
Location: Memphis, TN
Posts: 1,765
Thanks: 8
Thanked 123 Times in 121 Posts
harbingerOTV will become famous soon enough
http://roshanbh.com.np/2008/03/call-...nd-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/
__________________
Stop making things so hard on yourself.
i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis
harbingerOTV is offline   Reply With Quote
Users who have thanked harbingerOTV for this post:
Apocalypse (02-27-2011)
Old 02-26-2011, 07:59 PM   PM User | #5
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
Quote:
Originally Posted by Apocalypse View Post
I'm not very familiar with Ajax, and I'm not amazing with Java either. Can I get an example?
AJAX tutorial
bullant is offline   Reply With Quote
Old 02-27-2011, 11:33 PM   PM User | #6
Apocalypse
New to the CF scene

 
Join Date: Feb 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Apocalypse is an unknown quantity at this point
Quote:
Originally Posted by harbingerOTV View Post
http://roshanbh.com.np/2008/03/call-...nd-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.
Apocalypse is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, java, mysql, php, refresh

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:42 PM.


Advertisement
Log in to turn off these ads.