js 조작 Xml(서버 에 Xml 보 내기,서버 가 되 돌아 오 는 Xml 처리)(IE 에서 유효)

2517 단어 jsXml
프론트:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>js Xml( Xml, Xml)(IE )</title>
<script type="text/javascript"><!--
var xmlHttp = null;//XmlHttp ,Ajax
// Xml , .
function f(){
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");//1 xml ,Active .
xmlDoc.async = false;//
xmlDoc.loadXML("<root><name>tree</name><pwd>pwd</pwd></root>");

sendXml( xmlDoc,'Default.aspx');
}
// Xml
function sendXml(xmlDoc,serverURL){
xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP.3.0");//xmlhttp , .
var strDoc;
if (typeof(xmlDoc) == "object")// , object
strDoc = xmlDoc.xml;
else
strDoc = xmlDoc;

xmlHttp.open ("POST","Default.aspx" ,true);// , onreadystatechange 。
xmlHttp.onreadystatechange=getData;
xmlHttp.send(strDoc);// .
}
function getData(){
if (xmlHttp.readyState==4) // 4 .
{
var strxml=xmlHttp.responseText;// Xml
alert(strxml);
}
}

// --></script>
</head>
<body>
<input type="button" onclick="f();" value="request" />
</body>
</html>
Ajax Server:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Xml;

public partial class testXml_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Request.InputStream);// xml
XmlNode rootnode = xmldoc.DocumentElement;
XmlNode pwd = rootnode.SelectSingleNode("pwd");
pwd.InnerText = "changed";// xml

Response.Write(xmldoc.InnerXml);// Xml
Response.End();
}
}

좋은 웹페이지 즐겨찾기