View Single Post
Old 13-02-2008, 18:25   #6 (permalink)
Hunch
Grumpy old man
 
Hunch's Avatar
 
Join Date: Oct 2007
Location: North Japan
Posts: 1,617
A perfectly sensible question. Rather than making flippant responses (usually a sign someone has no idea what they're talking about) or debating whether or not it's a good idea, let's actually look at how it works (which is what the OP asked).

In AJAX, the XMLHttpRequest object has a property called onreadystatechange. Basically it's a value, which is updated as the request is processed. This allows the programmer to create an event handler, for example xmlHttp.onreadystatechange=function(), which triggers a function every time the state of the request changes. It's this function which handles the different messages displayed by the browser.


That might not mean much to you if you're not a programmer, so in simple terms, when you make an AJAX style request to the server, the browser stores a value from 0 to 4 indicating the following:

0 - Request not initialized
1 - Request set up
2 - Request sent
3 - Request being processed
4 - Request complete

An event handler is something which sits and listens for a particular change to happen in the state of the browser and triggers a bit of code to take care of it. So, after sending the request to the server, the state will be updated to '3' by the server to indicate the request is being processed, which is the time when the browser can trigger the function which creates the "processing - don't click refresh" page. When it gets to 4, the browser can then load the "completed" page.

Last edited by Hunch : 13-02-2008 at 18:38.
  Reply With Quote