Home > Backend Development > XML/RSS Tutorial > Share a method of delivering Xml documents using Ajax

Share a method of delivering Xml documents using Ajax

Y2J
Release: 2017-04-26 13:52:28
Original
1714 people have browsed it

Client

<script language="javascript"> 
//生成XML文件  
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;  
}  
///向服務器发送XML文档  
function Send(Str,URL)   
{  
    var Http = new ActiveXObject("Microsoft.XMLHTTP")  
    Http.open("POST",URL,false)  
    Http.send(Str)  
    return Http.responseText;  
}  
///获得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>
Copy after login

Server (test.cs)

System.IO.Stream stream = Request.InputStream 
System.Xml.XmlDocument doc = new XmlDocument();  
try  
{  
  doc.Load(stream); //加载发送过来的Xml文档 
}  
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);  
}  
//将doc处理后输出以便返回到客户端(此处省略) 
response.write("")
Copy after login

The above is the detailed content of Share a method of delivering Xml documents using Ajax. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template