HOME | J2ME | Struts | AJAX | SOAP | SOA MEDIA STREAMING AXIS |
AJAX STEP BY STEP
Introduction
XMLHttpRequest
Properties
Functions
First AJAX Program

 

 

AJAX: Functions of XMLHttpRequest

Back | Tutorial Home | Next

There are various functions associated with XMLHttpRequest which need to be used to complete AJAX life cycle. Following are the various functions of XMLHttpRequest object

  • abort()
  • getAllResponseHeaders()
  • getResponseHeader(header)
  • open(method, url)
  • send(body)
  • setRequestHeader(header, value)
abort()

Aborts the current executing request.

getAllResponseHeaders()

Use this method to get response headers as a key-value pairs separated by a colon

getResponseHeader(header)

Returns the value of the specified header.

open()

This method is used to populate the XmlHttpRequest object before firing a HTTP request to the server.  Simplest form of this method takes two values as parameters

Method: Can be GET, POST and PUT
URL: URL of the server URL

var url="/inc/word.php";
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url);

send()

This method finally sends the request to the server. This method has following method signature

send(String requestParameters)

requestParameters is null for GET method and a string similar to Query string in case of POST method. Lets see how we can do a login request using send() method

Send using GET 

var url="login.php?id=tom&pass=salsa123”;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

Send using POST

var url="login.php”;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.send(“id=tom&pass=salsa123”);

setRequestHeader()
This method is used to set a value to the request header
setRequestHeader(header, value)

foo.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

Back | Tutorial Home | Next

site comments powered by Disqus
Download our free toolbar

toolbar powered by Conduit

| Copyright © 2009. All rights reserved | Terms and Conditions | About | Contact | Feed Back |