Front desk:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>js manipulating XML (sending XML to the server, processing the XML returned by the server) (ie effective) </title>
<script type= "Text/javascript" ><!--
var xmlHttp = Null;//xmlhttp object, Ajax core
Create an XML document to send to the server.
function f () {
var xmldoc = new ActiveXObject ("msxml2.domdocument.3.0");//1 create XML object, active control.
Xmldoc.async = false;//Set asynchronous or non-asynchronous
Xmldoc.loadxml ("<root><name>tree</name><pwd>pwd</pwd></root>");
SendXML (xmldoc, ' default.aspx ');
}
Sending an XML document to the server
function SendXML (xmldoc,serverurl) {
XmlHttp = new ActiveXObject ("msxml2.xmlhttp.3.0");//xmlhttp object, asynchronous transfer.
var Strdoc;
if (typeof (xmldoc) = = "Object")//Judge, here is Object
Strdoc = Xmldoc.xml;
Else
Strdoc = xmldoc;
Xmlhttp.open ("POST", "default.aspx", true);//If the third argument is true, the callback function specified by the onReadyStateChange property is invoked.
Xmlhttp.onreadystatechange=getdata;
Xmlhttp.send (Strdoc);//data sent to the server.
}
function GetData () {
if (xmlhttp.readystate==4)//status is 4 for completion.
{
var strxml=xmlhttp.responsetext;//gets the returned XML
alert (strxml);
}
}
--></script>
<body>
<input type= "button" onclick= "f ();" value= "Request"/>
</body>
Ajax Server:
Copy Code code as follows:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
Public partial class TestXml_Default:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument ();
XmlDoc. Load (Request.inputstream),//receives the XML
XmlNode RootNode = xmldoc from the client. DocumentElement;
XmlNode pwd = RootNode. selectSingleNode ("pwd");
pwd. innertext = "changed";//server side changes XML document content
Response.Write (xmldoc. INNERXML)//Returns the modified XML document
Response.End ();
}
}