Closed Thread
Results 1 to 2 of 2

Thread: Updating a counter with AJAX

  1. #1
    archive02 is offline Newbie
    Join Date
    Nov 2006
    Posts
    10
    Rep Power
    0

    Updating a counter with AJAX

    The counter at the bottom of my website needs to be updated dynamically using the count() from MySQL and PHP. Now, how do I update this on the page without the user having to reload? I'm a bit confused on how to have JavaScript execute PHP code without forwarding the user to the new page.

    Anyone know how this is done?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    fahlyn's Avatar
    fahlyn is offline Learning Programmer
    Join Date
    Nov 2007
    Posts
    35
    Rep Power
    0
    Quote Originally Posted by archive02 View Post
    The counter at the bottom of my website needs to be updated dynamically using the count() from MySQL and PHP. Now, how do I update this on the page without the user having to reload? I'm a bit confused on how to have JavaScript execute PHP code without forwarding the user to the new page.

    Anyone know how this is done?
    What you'll need to do is probably setup a php script that will retrieve your count() and echo it. Then what you could do is have a JavaScript counter call that php script every 5 seconds (for example). Using AJAX you will be able to retrieve the value echoed from your php script in a JavaScript variable. I strongly recommend using prototype.js for ajax, it really takes care of handling all of the ugly XMLHTTPRequest stuff. It sounds like, if you're only going to be retrieving a counter you may want to use JSON...that way you will not have to parse XML in your JavaScript.

    I know all of that is at a pretty high level, but I'm not sure where you're at as far as familiarity with JavaScript and AJAX. Let me know if you need more detail, I'd be glad to elaborate and post some code examples.

    Happy Coding!
    -Fahlyn
    Visit My Google Group Here: Web Development Innovation

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Updating Table
    By iwrk4dedpr in forum Database & Database Programming
    Replies: 2
    Last Post: 11-07-2011, 12:10 PM
  2. WPF Updating
    By PGP_Protector in forum C# Programming
    Replies: 0
    Last Post: 03-30-2011, 03:00 PM
  3. Updating stdlibc++
    By ThemePark in forum Linux Applications
    Replies: 7
    Last Post: 12-14-2010, 05:10 PM
  4. Updating information
    By Jaan in forum PHP Development
    Replies: 3
    Last Post: 07-16-2008, 04:50 AM
  5. Updating a counter with AJAX
    By archive02 in forum JavaScript and CSS
    Replies: 0
    Last Post: 09-03-2007, 07:59 AM

Tags for this Thread

Bookmarks

Posting Permissions

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