Home / Articles / How To Use AJAX

How To Use AJAX

Article Description

AJAX, an acronym for Asynchronous JavaScript and XML, is very hot in the growing universe of Web development. While this new technology offers some great capabilities, it also sparks some unquestionable debate over issues with the Back button. Kris Hadlock explains how to use AJAX in a real-world situation and how you can assess its value in a project. By the time you finish reading this article, you'll know what AJAX is as well as where, why, and how to use it.

Like this article? We recommend

Adobe Photoshop CS2 Official JavaScript Reference

Adobe Photoshop CS2 Official JavaScript Reference

$39.99

Making the Request

Now that your request object has been created, you're ready to make a request to the server. Create a reference for an event handler to listen for onreadystatechange. The event handler method will then react when the state changes. We'll write this method as soon as we finish writing the request. Open the connection to GET or POST a custom URL, which in this case is the content.xml, and set a Boolean defining whether you want the call to be asynchronous.

It's time to send the request. In the example, I use null because we're using GET; to use POST, you would send a query string with this method:

request.onreadystatechange = onResponse;
request.open("GET". url, true);
request.send(null);
6. Custom Loading and Error Handling Messages | Next Section Previous Section