Using AJAX to pass XML documents _ practical skills
Source: Internet
Author: User
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")
Http.open ("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.async=false
Dom.loadxml (Strxml)
if (Dom.parseError.errorCode!= 0)
{
Delete (Dom)
Return (false)
}
Else
{
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");
}
</script>
Server Side (Test.cs)
System.IO.Stream Stream = Request.inputstream
System.Xml.XmlDocument doc = new XmlDocument ();
Try
{
Doc. Load (stream); Load the XML document sent over
}
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 doc after processing to return to the client (omitted here)
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.