To clarify what AJAX is and how it works:
AJAX stands for
Asynchronous Javascript And XML
It is a
technique in Javascript that allows the programmer to have scripts download and use data from the server, without having to reload the page.
An XMLHttp Javascript object will hereby function as a browser, it uses the HTTP protocol to request a page, and then the content of that page can be read by Javscript once the request is completed.
- User browses to page A with his browser, the browser will request page A from the server.
- Server sends page A to browser, which displays it on the users screen. Page A contains Javascript.
- Javascript initiates a XMLHttp object and requests a page B (with optional GET or POST data, which can be retrieved from formfields or such)
- Server sends page B back to the Javascript XMLHttp object on page A in the browser.
- The XMLHttp object will update its readystate, and the Javascript recognizes that the request is complete (or failed).
- Javascript reads contents of page B, and (possibly) inserts it into page A in the browser
That way, the website can still download content from other pages on demand (or download PHP-generated data like a chatmessage), without the user having to wait untill the entire page is downloaded and displayed.
For a good tutorial on working with AJAX / XMLHttp, please visit
w3schools.com/ajax