重要语句
xmlHttp.open("POST", "receive.aspx?type=xmlsave", true);
xmlHttp.send(xmlDoc);
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function parseXML() {
try //Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
catch (e) {
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc = document.implementation.createDocument("", "", null);
}
catch (e) {
alert(e.message);
return;
}
}
xmlDoc.async = false; //如果xml载入终了实行以下
xmlDoc.load("note.xml");
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue = "yaomingming";
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange = function() { //onreadystatechange 属性存有处置惩罚服务器相应的函数
if (xmlHttp.readyState == 4) { //readyState 属性存有服务器相应的状况信息
document.getElementById("to").innerHTML = xmlHttp.responseText; //经由过程 responseText 属性来取回由服务器返回的数据
}
}
xmlHttp.open("POST", "receive.aspx?type=xmlsave", true);
// open() 要领须要三个参数。第一个参数定义发送要求所运用的要领(GET 照样 POST)。第二个参数划定服务器端剧本的 URL。第三个参数划定应该对要求举行异步地处置惩罚。
xmlHttp.send(xmlDoc); //send() 要领可将要求送往服务器
}</script>
</head>
<body onload="parseXML()">
<form id="form1" runat="server">
<p><span id="to"></span>
</p>
</form>
</body>
</html>
receive.aspx.cs
System.IO.Stream instream = Page.Request.InputStream;
BinaryReader br = new BinaryReader(instream, System.Text.Encoding.UTF8);
byte[] byt = br.ReadBytes((int)instream.Length);
string sXml = System.Text.Encoding.UTF8.GetString(byt);
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(sXml);
xmlDoc.Save(Server.MapPath("note.xml"));
Response.Write("save");
以上就是XML进修(三) js保留xml的示例代码分享的细致内容,更多请关注ki4网别的相干文章!