The code is as follows:
<script type= "Text/javascript" >varXMLHTTP; functionSubmit () {//1. Create a XMLHttpRequest object if(window. XMLHttpRequest) {//Ie7,ie8,firefox, otherXMLHTTP =NewXMLHttpRequest (); if(xmlhttp.overridemimetype) {//bug fixes for certain specific versions of Mozillar browserXmlhttp.overridemimetype ("Text/xml"); } } Else if(window. ActiveXObject) {//ie6,ie5.5,ie5XMLHTTP =NewActiveXObject ("Microsoft.XMLHTTP"); } //simple notation, should also be able to //xmlhttp = new XMLHttpRequest () | | new ActiveXObject ("Microsoft.XMLHTTP"); if(xmlhttp = = Undefined | | xmlhttp = =NULL) {alert (' The current browser does not support the creation of XMLHttpRequest objects, please replace the browser! ‘); return; } //save each state to an arrayArray.push (xmlhttp.readystate); //2. Registration callback method CallbackXmlhttp.onreadystatechange =callback; //Get Client Content varUserName = document.getElementById ("UserName"). Value; /*//get Request mode//3. Set the corresponding parameters of the server-side interaction Xmlhttp.open ("Get", "Ajaxrequst.ashx?name=" +username, true); 4. Set to send data to the server, start and service side interactive xmlhttp.send (); */ //Post Request Mode //3. Setting the appropriate parameters for server-side interactionXmlhttp.open ("Post", "Ajaxrequst.ashx",true); //The Post method requires additional codeXmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); //4. Set up to send data to the server, start and service side interactionXmlhttp.send ("name=" +userName); } functioncallback () {//5. Determine whether the server side of the interaction is complete, but also to determine whether the service side of the correct return of the data if(Xmlhttp.readystate = = 4) { //indicates that the interaction with the server has been completed if(Xmlhttp.status = = 200) { //indicates that the server's response code is 200, and the correct return data //How to accept pure file data varMessage =Xmlhttp.responsetext; //Add the returned content to the DIV layer vardiv = document.getElementById (' message ')); Div.innerhtml=message; //How to accept the DOM object corresponding to the XML data //The premise is that the server side needs to be set Content-type to Text/xml //var domxml = xmlhttp.responsexml; } } } </script>
Full AJAX notation (multi-browser support)