ATTN: AJAX GODS - help needed for auto page refresh

Discussion in 'Web Design and Development' started by jo0, Jan 6, 2010.

  1. jo0 macrumors regular

    Nov 25, 2009
    Seattle, WA

    having a tough time getting the results that i want on one of my projects.

    the project is: (make fun if you need to...i accept criticism.)

    if you look at the source it basically gets the date while the page loads and uses variables to determine whether a NO or YES will show in response to whether it is a postal holiday or not. simple really.

    what i want:

    i want to make it so that the page reloads every 5 - 10 seconds so that the date rechecks and is updated as needed. i want to do this in ajax, so the page doesn't actually have to do a typical reload; i want the feature ajax is known for, i want it to just suddenly change if it needs to.

    i've played with a few samples and scripts i found online, but there are few resources that seem anywhere close to what i need.

    i hate web code.

    any help appreciated for the ajax noob

  2. angelwatt Moderator emeritus


    Aug 16, 2005
    So you know, what you want is not AJAX, simply JavaScript. AJAX deals with doing server side processing and returning results. You're simply after changing page content dynamically without a page refresh, which is what JavaScript is good for. It's a common mistake.

    The best bet for your situation is to use the setTimeout or setInterval functions to take page actions every so often.

    Pseudo Code:
    function CheckHoliday {
    setTimeout(CheckHoliday8000); // in 8 seconds
  3. angelwatt Moderator emeritus


    Aug 16, 2005
    More or less, no PHP though. Just remember I said that was pseudo code, which means you can't just copy and paste it. You'll also need to change the way you change text on-screen. You currently use the document write function, but you'll need to use the .innerHTML attribute to swap text on-screen.

Share This Page