O'Reilly logo

JavaScript® 24-Hour Trainer by Jeremy McPeak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 32. Using XMLHttpRequest Objects

In Lesson 31 you learned that there are a variety of ways to incorporate Ajax into a web application. The older technique of using hidden frames can still be found in many modern web applications, but the most popular way to add Ajax functionality to an application is by using the XMLHttpRequest (XHR) object. Despite its name, you can retrieve more than XML with XHR. In fact, it's more commonly used to retrieve plain text.

The XHR object originated as a component, called XmlHttp, in Microsoft's MSXML library. The component was first released with Internet Explorer (IE) 5. XmlHttp allowed developers to make HTTP requests, using JavaScript or VBScript, to retrieve XML data. Microsoft updated the MSXML library with every major version of IE, and each new version included an improved XmlHttp component.

As the popularity of Microsoft's XmlHttp grew, the developers behind Mozilla built their own version (calling it XMLHttpRequest) for Firefox. Even though it had a different name, the Mozilla developers copied the majority of the properties and methods of Microsoft's XmlHttp, making cross-browser use easier. Soon after, the developers of Opera and Safari copied Mozilla's XHR object, making transparent HTTP requests through pure JavaScript possible in all modern browsers.

CREATING XHR OBJECTS

There are essentially two types of browsers when it comes to XHR support. The first supports the native XHR object—meaning that XHR is built into the browser. The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required