XML DOM - HttpRequest object

## XML DOM Tutorial

DOM HOME DOM Introduction DOM Nodes DOM Node Tree DOM Parser DOM Load Function DOM Methods DOM Accessing DOM Node Info DOM Node List DOM Traversing DOM Browsers DOM Navigating

## Manipulate Nodes

DOM Get Values DOM Change Nodes DOM Remove Nodes DOM Replace Nodes DOM Create Nodes DOM Add Nodes DOM Clone Nodes DOM XMLHttpRequest

## XML DOM Reference

DOM Node Types DOM Node DOM NodeList DOM NamedNodeMap DOM Document DOM DocumentImpl DOM DocumentType DOM ProcessingInstr DOM Element DOM Attribute DOM Text DOM CDATA DOM Comment DOM XMLHttpRequest DOM ParseError Obj DOM Parser Errors
DOM Summary

## XML DOM Examples

DOM Examples DOM Validator

# The XMLHttpRequest Object

« Previous
Next Chapter »

With the XMLHttpRequest object you can update parts of a web page, without reloading the whole page.

## Try it Yourself - Examples

A simple XMLHttpRequest example
Create a simple XMLHttpRequest, and retrieve data from a TXT file.

Retrieve header information with getAllResponseHeaders()
Retrieve header information of a resource (file).

Retrieve specific header information with getResponseHeader()
Retrieve specific header information of a resource (file).

Retrieve the content of an ASP file
How a web page can communicate with a web server while a user type characters in an input field.

Retrieve content from a database
How a web page can fetch information from a database with the XMLHttpRequest object.

Retrieve the content of an XML file
Create an XMLHttpRequest to retrieve data from an XML file and display the data in an HTML table.

## The XMLHttpRequest Object

The XMLHttpRequest object is used to exchange data with a server behind the scenes.

The XMLHttpRequest object is the developers dream, because you can:

- Update a web page without reloading the page
- Request data from a server after the page has loaded
- Receive data from a server after the page has loaded
- Send data to a server in the background

## XMLHttpRequest Object Methods

Method | Description
--- | ---
abort() | Cancels the current request
getAllResponseHeaders() | Returns header information
getResponseHeader() | Returns specific header information
open(method,url,async,uname,pswd) | Specifies the type of request, the URL, if the request should be handled asynchronously or not, and other optional attributes of a request method: the type of request: GET or POST url: the location of the file on the server async: true (asynchronous) or false (synchronous)
send(string) | send(string) Sends the request off to the server. string: Only used for POST requests
setRequestHeader() | Adds a label/value pair to the header to be sent

## XMLHttpRequest Object Properties

Property | Description
--- | ---
onreadystatechange | Stores a function (or the name of a function) to be called automatically each time the readyState property changes

readyState

Holds the status of the XMLHttpRequest. Changes from 0 to 4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready

responseText | Returns the response data as a string
responseXML | Returns the response data as XML data
status | Returns the status-number (e.g. "404" for "Not Found" or "200" for "OK")
statusText | Returns the status-text (e.g. "Not Found" or "OK")

« Previous
Next Chapter »

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE