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.<%response.setcontenttype ("Text/xml");%>
Zjcfan