What is ajax:
want more details click here
ere we have seen 2 files.
it will work both ie and opera and firefox.
First we initialise the xmlhttprequest object..
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
xmlhttp = new XMLHttpRequest();
alert("Your browser is not supporting XMLHTTPRequest");
xmlhttp = false;
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var request = creat_Object();
Once an XMLHttpRequest object has been created, we must call two separate methods in order to get it to retrieve data from a server.
open() initialises the connection we wish to make, and takes two arguments, with several optionals. The first argument is the type of request we want to send; the second argument identifies the location from which we wish to request data. For instance, if we wanted to use a GET request to access asp_server.asp at the root of our server, we'd initialise the XMLHttpRequest object like this:
The URL can be either relative or absolute, but due to cross-domain security concerns, the target must reside on the same domain as the page that requests it.
The open() method also takes an optional third boolean argument that specifies whether the request is made asynchronously (true, the default) or synchronously (false). With a synchronous request, the browser will freeze, disallowing any user interaction, until the object has completed. An asynchronous request occurs in the background, allowing other scripts to run and letting the user continue to access their browser. It's recommended that you use asynchronous requests; otherwise, we run the risk of a user's browser locking up while they wait for a request that went awry. open()'s optional fourth and fifth arguments are a username and password for authentication when accessing a password-protected URL.
Once open() has been used to initialise a connection, the send() method activates the connection and makes the request. send() takes one argument, allowing us to send extra data, such as asp querystring variables, along with the call.
Here just we get the data from asp_server.asp file so we dont want use query string variables...
request.onreadystatechange = sever_interaction;
once we've called send(), XMLHttpRequest will contact the server and retrieve the data we requested; however, this process takes an indeterminate amount of time. In order to find out when the object has finished retrieving data, we must use an event listener. In the case of an XMLHttpRequest object, we need to listen for changes in its readyState variable. This variable specifies the status of the object's connection, and can be any of the following:
0 – Uninitialised
1 – Loading
2 – Loaded
3 – Interactive
4 – Completed
Changes in the readyState variable can be monitored using a special onreadystatechange listener, so we'll need to set up a function to handle the event when the readyState is changed here we use that function name is sever_interaction()
readyState increments from 0 to 4, and the onreadystatechange event is triggered for each increment, but we really only want to know when the connection has completed (4), so our handling function needs to realise this. Upon the connection's completion, we also have to check whether the XMLHttpRequest object successfully retrieved the data, or was given an error code, such as 404: "Page not found". This can be determined from the object's status property, which contains an integer code. "200" denotes a successful completion, but this value can be any of the HTTP codes that servers may return.
if(request.readyState == 1)
document.getElementById('aja_cnts').innerHTML = 'Loading...';
if(request.readyState == 4)
if (request.status == 200)
var answer = request.responseText;
document.getElementById('aja_cnts').innerHTML = answer;
Even though the XMLHttpRequest object allows us to call the open() method multiple times, each object can really only be used for one call, as the onreadystatechange event doesn't update again once readyState changes to "4" (in Mozilla). Therefore, we have to create a new XMLHttpRequest object every time we want to make a remote call.
v_nme="name : New Begin"
v_city="City : Chennai"
Response.Write(v_nme&"Sample from Server "&v_city)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"<A href="http:<html xmlns="<A href="http:<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Getting Server side data using AJAX</title>