Easy learning with example program codes

ajax xmlhttprequest tutorial

Ajax refers to asynchronous java script and xml. It is not a not a programming language. Ajax is of Asynchronous type. It normally uses XML, plain text or JSON to communicate with server i.e. for data transfer.

Note: Ajax is technology independent.

The XMLHttpRequest object is used for asynchronous communication between client and server. It provides the facility to update the web page content without reloading the whole page.

How to create an xmlhttprequest object

Var variable = new XMLHttpRequest();


Ajax XMLHttpRequest Object Methods


Method Description
new XMLHttpRequest() It creates a new XMLHttpRequest object.
abort() It cancels the current request.
getAllResponseHeaders() It returns header information.
getResponseHeader() It returns specific header information.
open(method,url,async,user,psw) It specifies the request.
method: the request type GET or POST
url: the file location
async: true (asynchronous) or false (synchronous)
user: optional user name
psw: optional password
send() It sends the request to the server. It is used for GET requests
send(string) It sends the request to the server. It is used for POST requests
setRequestHeader() It adds a label or value pair to the header to be sent


Ajax XMLHttpRequest Object Properties


Property Description
onreadystatechange It defines a function to be called when the readyState property changes
readyState It holds the status of the XMLHttpRequest.

XMLHttpRequest Status:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready

responseText It returns the response data as a string.
responseXML It returns the response data as XML data.
status It returns the status-number of a request. For example:
200: “OK”
403: “Forbidden”
404: “Not Found”
statusText It returns the status-text (For example “OK” or “Not Found”).



Posted in Ajax   
Sign Up/ Sign In
Ask a Question

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2018 CodesJava Protection Status SiteMap Reference: Java Wiki