You might be a little tired of
XMLHttpRequest -- I rarely read an entire article about a single object, especially one that is this simple. However, you will use this object over and over again in each page and application that you write that uses Ajax. Truth be told, there's quite a bit still to be said about
XMLHttpRequest. In coming articles, you'll learn to use
POST in addition to
GET in your requests, set and read content headers in your request as well as the response from the server; you'll understand how to encode your requests and even handle XML in your request/response model.
Quite a bit further down the line, you'll also see some of the popular Ajax toolkits that are available. These toolkits actually abstract away most of the details discussed in this article and make Ajax programming easier. You might even wonder why you have to code all this low-level detail when toolkits are so readily available. The answer is, it's awfully hard to figure out what goes wrong in your application if you don't understand what is going on in your application.
So don't ignore these details or speed through them; when your handy-dandy toolkit creates an error, you won't be stuck scratching your head and sending an email to support. With an understanding of how to use
XMLHttpRequest directly, you'll find it easy to debug and fix even the strangest problems. Toolkits are fine unless you count on them to take care of all your problems.
So get comfortable with
XMLHttpRequest. In fact, if you have Ajax code running that uses a toolkit, try to rewrite it using just the
XMLHttpRequest object and its properties and methods. It will be a great exercise and probably help you understand what's going on a lot better.
In the next article, you'll dig even deeper into this object, exploring some of its tricker properties (like
responseXML), as well as how to use
POST requests and send data in several different formats.
Validator and Debugger!