Use ajax to pass XML documents

Source: Internet
Author: User

Client

<Script language = "JavaScript">

// Generate an 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 the XML document to the server
Function send (STR, URL)
{
VaR HTTP = new activexobject ("Microsoft. XMLHTTP ")
HTTP. Open ("Post", URL, false)
HTTP. Send (STR)
Return HTTP. responsetext;
}

/// Get the value of the specified section in XML
Function getxmlnodevalue (strxml, nodename)
{
VaR dom = new activexobject ("Microsoft. xmldom ")
Dom. async = false
Dom. loadxml (strxml)
If (DOM. parseerror. errorcode! = 0)
{
Delete (DOM)
Return (false)
}
Else
{
VaR node = dom.doc umentelement. 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 ");
}
</SCRIPT>

Server (test. CS)

System. Io. Stream stream = request. inputstream
System. xml. xmldocument Doc = new xmldocument ();
Try
{
Doc. Load (Stream); // load the XML file sent
}
Catch
{
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 the doc after processing to return it to the client (omitted here)

Response. Write ("")

Related Article

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.