What is XMLHttpRequest?
Posted on April 21st, 2009 by Gabriel HarperWhat 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:
- Initialize & test the XMLHttpRequest object
- Register a handler that is triggered when the request completes
- Open a connection and send the GET or POST request
- 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.
April 21st, 2009 at 1:29 pm
[...] 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 [...]
April 22nd, 2009 at 12:59 pm
[...] Home Business Software Books Working Online SEO « What is XMLHttpRequest? [...]