如何利用Ajax傳遞Xml文檔教程詳解

來源:互聯網
上載者:User
用戶端

<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>


伺服器端(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("")
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.