XMLHttpRequest object
XMLHttpRequest object
The XMLHttpRequest object is used to exchange data with the server behind the scenes.
The XMLHttpRequest object is a developer's dream because you can:
Update web page without reloading the page
Request data from server after page has loaded
Receive data from server after page has loaded
Send data to the server in the background
To learn more about the XMLHttpRequest object, take our XML DOM tutorial.
XMLHttpRequest instance
When you type a character in the following input field, an XMLHttpRequest is sent to the server - returning name suggestions (from a file on the server):
Type a letter in the input box: initials suggestion: |
All modern browsers (IE7+, Firefox, Chrome, Safari and Opera) have built-in XMLHttpRequest objects.
Syntax for creating XMLHttpRequest objects:
xmlhttp=new XMLHttpRequest();
ActiveX objects are used in older versions of Internet Explorer (IE5 and IE6):
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
In the next chapter, we will use the XMLHttpRequest object to retrieve XML information from the server.