Using AJAX to deliver XML documents

Source: Internet
Author: User
Tags return client


<script language= "JavaScript" >

Generate XML file
function Getallformdata ()
var strxml = "<client>\r\n<formdata>\r\n";
Strxml = "<UserName>bccu</UserName>"
Strxml = "<Age>25</Age>";
Strxml = "</FormData>\r\n</Client>"
return strxml;

Send an XML document to a service
function Send (Str,url)
var Http = new ActiveXObject ("Microsoft.XMLHTTP") ("POST", Url,false)
Http.send (STR)
return http.responsetext;

Gets the value of the section specified in the XML
function Getxmlnodevalue (strxml,nodename)
var Dom = new ActiveXObject ("Microsoft.XMLDOM")
Dom.loadxml (Strxml)
if (Dom.parseError.errorCode!= 0)
Delete (Dom)
Return (false)
var node = Dom.documentElement.selectSingleNode ("//" +nodename);
if (node)
NodeValue = Node.text;
Delete (Dom)
return (NodeValue);

function Test ()
var tmp = Send (Getallformdata (), "./test.aspx");
var name = Getxmlnodevalue (tmp, "UserName");
var password = getxmlnodevalue (tmp, "age");

Server Side (Test.cs)

System.IO.Stream Stream = Request.inputstream
System.Xml.XmlDocument doc = new XmlDocument ();
Doc. Load (stream); Load the XML document sent over
byte[] buffer = new Byte[stream. Length];
Stream. Read (Buffer,0,buffer. Length);
String strxml = System.Text.UnicodeEncoding.Default.GetString (buffer,0,buffer. Length);
Doc. Loadxml (strxml);

Output doc after processing to return to the client (omitted here)

Response.Write ("")


Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.