Home » Scriptalicious Blog » Webmaster » What is XMLHttpRequest?

Scriptalicious Blog

What is XMLHttpRequest?

Posted 2009-04-21 in Webmaster

Scriptalicious Blog

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.




Subscribe via RSS

Stay current with Scriptalicious news and subscribe in your favorite RSS reader.

Subscribe by RSS

Subscribe via Email

Get the latest Scriptalicious news delivered to your inbox.

77 powerful SEO scripts for under $100.

Real-time Backlink Rank Checker script.

Scriptalicious is in no way affiliated with myspace.com® or Google®. Google, PageRank™ and MySpace are the trademarks of their owners.