1. Establish XMLHttpRequest objects
if (window. XMLHttpRequest) {
XmlHttp = new XMLHttpRequest ();
if (Xmlhttp.overridemimetype) {
Xmlhttp.overridemimetype ("Text/xml");
}
}else if (window. ActiveXObject) {
var activename =["MSXML2. XMLHTTP "," Microsoft.XMLHTTP "];
for (var i=0; i<activename.length; i++) {
try{
XmlHttp = new ActiveXObject (Activename[i]);
Break
}catch (e) {
}
}
}
if (!xmlhttp) {
Alert ("Create XMLHttpRequest object Failed");
}else{
}
2. Set callback function
Xmlhttp.onreadystatechange= callback;
function callback () {}
3. Use the Open method to establish a connection with the server Xmlhttp.open ("Get", "ajax?name=" + name,true)
This step is to set the request for HTTP (post/get), and if it is post, pay attention to setting the request header information Xmlhttp.setrequestheader ("Content-type", "application/ X-www-form-urlencoded ")
4. Send data to server side
Xmlhttp.send (NULL);
If the Post method is not empty
5. Handling in a callback function for different response states
if (xmlhttp.readystate = = 4) {
Determine if the interaction is successful
if (Xmlhttp.status = = 200) {
Get data returned by the server
Get Plain Text data
var responsetext =xmlhttp.responsetext;
document.getElementById ("Info"). InnerHTML = ResponseText;
}
}