Client Code
1<script>2 varIsie =true;3 varXMLHTTP =NULL;4 functionCreatexmlhttp () {//Create a Xmlxmlhttprequest object5 if(xmlhttp = =NULL) {6 if(window. XMLHttpRequest) {7XMLHTTP =NewXMLHttpRequest ();8 }9 Else {TenXMLHTTP =NewActiveXObject ("Microsoft.XMLHTTP"); One } A //if (xmlhttp = = null) { - //alert (' Your browser does not support Ajax '); - //} the } - if($.browser.msie) {//IE Browser -Isie =true; - } + Else { -Isie =false; + } A at } - //creating an XML document that object is also the first step - functionCreatedomxml () { - varDomxml =NULL; - //IE Browser creates an XML DOM object - varsigns = ["msxml2.domdocument.5.0", "msxml2.domdocument.4.0", in -"msxml2.domdocument.3.0", "Msxml2.domdocument", "Microsoft.XMLDOM"]; to for(vari = 0; i < signs.length; i++) { + Try { -Domxml =NewActiveXObject (Signs[i]); the Break; * } $ Catch(e) {}Panax Notoginseng } - the //Other Browsers + if(Domxml = =NULL) ADomxml = Document.implementation.createDocument ("", "",NULL); the returnDomxml; + } - //The second step: The client gets the data to write in the XML Document Object $ functionCreatexml (DOM) { $ varRoot = doc.createelement ("root");//Create a root node - varassign_id = doc.createelement ("id");//child Nodes - varAssign_ans = doc.createelement ("answer");//child Nodes the if(Isie) { -Assign_id.text = "1";WuyiAssign_ans.text = "1"; the } - Else { WuAssign_id.textcontent = "1"; -Assign_ans.textcontent = "1"; About } $ - - Root.appendchild (assign_id); - A Root.appendchild (Assign_ans); + the dom.appendchild (choose); - } $ functionSubmit () { the varDom =createdomxml (); the createxmlhttp (); the if(xmlhttp = =NULL) { theAlert ("Your browser does not support Ajax, please try a different browser"); - return0; in } the Createxml (DOM); the AboutXmlhttp.onreadystatechange =success; theXmlhttp.open ("Post", "Test.aspx",true);//Receive Request page the //Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); the Xmlhttp.send (DOM); + } - the functionSuccess ()//Asynchronous handler function when the service returns successfullyBayi { the if(Xmlhttp.readystate = = 4) { the alert (xmlhttp.status); - if(Xmlhttp.status = = 200) { - alert (xmlhttp.responsetext); the } the Else { theAlert ("Test Error"); the } - } the } the</script>
Server-side code
1ProtectedvoidPage_Load (object sender, EventArgs e)2 {3 string res;4request.contentencoding = System.Text.Encoding.GetEncoding ("UTF-8");5XmlDocument xmldoc =NewXmlDocument ();6 xmldoc.load (request.inputstream);7XmlNode node = xmldoc.selectsinglenode ("Choose");8foreach (XmlNode childinchnode. ChildNodes)9 {TenRes +Child.innertext; One } A Response.Write (res); - Response.End (); - } the}