What is XMLHttpRequest?

Posted on April 21st, 2009 by Gabriel Harper

What is XMLHttpRequest? The XMLHttpRequest object enables client-server requests in JavaScript. If you’re writing Ajax enabled scripts, fetching remote data in a Firefox extension, or pulling data from another URL in any JavaScript app then XMLHttpRequest is needed.

XMLHttpRequest is a scripting object that provides an interface for client-server requests. XMLHttpRequest originated with Internet Explorer 5, was eventually picked up by Mozilla, and is currently a W3C working draft specification. You can actually fetch data from a file, FTP server, and other protocols not limited to HTTP.

Simply put, you use XMLHttpRequest to grab data from another site with JavaScript.  The basic steps are:

  1. Initialize & test the XMLHttpRequest object
  2. Register a handler that is triggered when the request completes
  3. Open a connection and send the GET or POST request
  4. Check the response status and do something with the response

There are already some good simple examples of using XMLHttpRequest, and more in-depth implementations with better browser compatibility and structure. For Firefox extension developers the MDC describes using XMLHttpRequest in Mozilla/Firefox with lots of detail, and in a format suitable for add-on developers.

There are some distinct advantages of transparent client-server requests in Web applications. Instead of making a full GET or POST request and reloading the page, you can fetch data from multiple sources in the background. You can present live updating data on a Web page or toolbar. Most importantly, you can spare your users the frustration of waiting around and enhance  the entire user experience.

Browser compatibility with XMLHttpRequest varies, but most modern browsers support some implementation of it. Always try to have a fallback in place for those who have incomplete or buggy browsers.

2 Responses to “What is XMLHttpRequest?”

  1. AJAX APPS W/ XMLHTTPREQUEST | AJAX Says:

    [...] in their JavaScript implementation. If you aren’t already familiar with it you should explore What is XMLHttpRequest for details, usage examples and history of XMLHttpRequest. By implementing dynamic data with [...]

  2. REMOTE DATA IN A FIREFOX TOOLBAR EXTENSION Says:

    [...] Home Business Software Books Working Online SEO « What is XMLHttpRequest? [...]

Leave a Reply


Intavant          Servermind

©2020 Gabriel Harper. Do not use, copy or re-publish any part of this blog.