Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    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.

  • Users who have thanked bullant for this post:

    akosiana (02-26-2011)

  • #3
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I'm not very familiar with Ajax, and I'm not amazing with Java either. Can I get an example?

  • #4
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,801
    Thanks
    8
    Thanked 131 Times in 129 Posts
    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

  • Users who have thanked harbingerOTV for this post:

    Apocalypse (02-28-2011)

  • #5
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    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

  • #6
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •