1. Xmlhttp is a browser object that can be used to simulate HTTP GET and POST requests. Cooperating with JavaScript, it can realize the regular data update of page data without refreshing . If it is used in chat rooms and text live broadcasts, it can achieve better visual effects.
2. XmlHttp is implemented as an ActiveX object in IE, usually using var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); you can also use var xmlhttp = createobject("MiCROSOFT.XMLHTTP") to create an object, and then use the object The open method to issue an Http request.
3. Code example:
var strURL = admin; function xmlhttpPost(cell,strURL,action) { var xmlHttpReq = false; var self = this; if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); } else if (window.ActiveXObject) { self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } self.xmlHttpReq.open('POST', strURL, true);//Will enter the corresponding servlet self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4 ) { if(self.xmlHttpReq.status==200){ // updatepage(self.xmlHttpReq.responseText,responsediv); var responseMsg = self.xmlHttpReq.responseText; responseEvent(cell,responseMsg); }else{ alert('Ajax Request Error.'); } } } self.xmlHttpReq.send(action); }
application/x-www-form-urlencoded: key-value pair form submission
When the action is get, the browser uses the x-www-form-urlencoded encoding method to convert the form data into a string (name1=value1&name2=value2...), and then appends the string to the back of the url, separated by ? , load this new url. When the action is post, the browser encapsulates the form data into the http body and sends it to the server.
// The requested status has 5 values: 0=uninitialized; 1=loading; 2=loaded; 3=interactive; 4=completed; if (xmlHttpReq.readyState == 4) { // 200 corresponds to OK, such as 404 = page not found if (xmlHttpReq.status == 200) { // alert(xmlHttpReq.responseText); } } refer to: 1.http://blog.csdn.net/main_xtgjfge/article/details/18960409