WWW FAQs: What is AJAX?


2005-11-21: AJAX, or Asynchronous JavaScript and XML, is a new way for web pages to send and receive data to and from a web site without forcing the user to wait for a new page to load.

True AJAX applications, like Google's gmail or my live support example, have certain things in common:

  • They can use a standard web browser, such as Firefox, Internet Explorer or Safari, as their only user interface.
  • They don't force the user to wait for the web server every time the user clicks a button. This is what "asynchronous" means. For instance, gmail fetches new email messages in the background ("asynchronously") without forcing the user to wait. This makes an AJAX application respond much more like a "real" application on the user's computer, such as Microsoft Outlook.
  • They use standard JavaScript features (including the unofficial XMLHTTPRequest standard, pioneered by Microsoft and adopted by Firefox and other browsers) to fetch data in the background and display different email messages or other data "on the fly" when the user clicks on appropriate parts of the interface.
  • Usually they manipulate data in XML format. This allows AJAX applications to interact easily with server-side code written in a variety of languages, such as PHP, Perl/CGI, Python and ASP.NET. Using XML isn't absolutely necessary, and in fact many "AJAX" applications don't -- they use the XMLHTTPRequest object to send and receive data "on the fly," but they don't actually bother packaging that data as XML.
For a complete introduction to AJAX programming, see How do I fetch data from the server without loading a new page?
Most AJAX applications use XML only for data coming from the server to the browser, and sometimes not even then. XMLHTTPRequest can accommodate other data formats just as easily, and parsing is often faster when XML is not used. For communications from the browser to the server, submitting the data like a conventional POST form submission is the most common method. Built-in features of server-side languages like ASP and PHP can easily understand data that arrives that way and respond with XML, or another format that the JavaScript client has been designed to understand.

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!