Ajax is the name of the magic, I first saw it was also attracted by it, it is asynchronous JavaScript and XML, asynchronous JavaScript and XML, the introduction of Ajax on the internet introduced too much, I don't have much more, My eloquence is not good, not what they say so wonderful, can go to Http://zh.wikipedia.org/wiki/AJAX to see, here I just give everybody an example, understand how to use AJAX.
Ajax the most interesting place is that you can not refresh the page and can interact with the background, do not need to refresh the page to achieve a smooth transition between Web pages and Web pages. Using AJAX, you don't need to install a new plugin, just ask your browser to support JavaScript.
First you need your JavaScript object XMLHttpRequest, which is the core of Ajax, we all work around it, and we can get one from the following code:
if (window.XMLHttpRequest){
xmlObj = new XMLHttpRequest();
}else if (window.ActiveXObject){
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
}
We send the request to the service through the open method of this object,
The function is declared as Xmlhttprequest.open (string method, String URL, Boolean asynchronous);
Method is the way it is requested and can be used for get and post
URL is the resource you want to request
Asynchronous is a Boolean type, and True indicates that the interaction is set to asynchronous
xmlObj.open("GET",URL,true);
xmlObj.send("");
Calling Send () (parameter is null or NULL) will initiate a request.
For a get-way request, two times the same request will have the same result,
Because you want to set the interaction to asynchronous, you specify a callback function:
Xmlobj.onreadystatechange = callbackfunction;
The rest of the work is handled by the callback function.
One thing to note is that when you respond to an asynchronous request with a servlet or JSP,
The ContentType property to set the reponse indicates an XML format:
Response.setcontenttype ("Text/xml");
Everything's ready, so let's do a simple asynchronous request and display the result of the request return:
Client:
Send Request
Look here!
Here's data.jsp.
Zjcfan