Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jo0

macrumors regular
Original poster
Nov 25, 2009
224
0
Seattle, WA
ATTN: AJAX GODS


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

the project is: www.willthemailmancometoday.com (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

-jo0
 
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:
PHP:
function CheckHoliday {
  DateProcessing();
  setTimeout(CheckHoliday, 8000); // in 8 seconds
}
CheckHoliday();
 
so in this case could i wrap [...] around the already existing javascript in the page (see source of my page) or make an actual php page...?

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.