JS operation XML (sending XML to the server, processing the XML returned by the server) (effective under IE) _javascript tips

Source: Internet
Author: User
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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.