javascript修改了xml,怎么才能把xml返回到后台,通过asp.net C#将修改好的xml文件保存!!!下面源代码
前台:<htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title></title></hea...
前台:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" action="Default2.aspx">
<div>
<asp:Button ID="Button1" runat="server" Text="ADD" onclick="Button1_Click" />
<script type="text/javascript" src="loadxmldoc.js">
window.onload = function () {
xmlDoc = loadXMLDoc("books.xml");
var x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
document.write(x.nodeValue);
x.insertData(0, "Hello ");
document.write("<br />");
document.write(x.nodeValue);
xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "Default2.aspx", false);
xmlHttp.send(xmlDoc);
}
</script>
</div>
</form>
</body>
</html>
后台;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument dom = new XmlDocument();
dom.Load(Request.InputStream);
dom.Save(Server.MapPath("books.xml"));
}
} 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" action="Default2.aspx">
<div>
<asp:Button ID="Button1" runat="server" Text="ADD" onclick="Button1_Click" />
<script type="text/javascript" src="loadxmldoc.js">
window.onload = function () {
xmlDoc = loadXMLDoc("books.xml");
var x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
document.write(x.nodeValue);
x.insertData(0, "Hello ");
document.write("<br />");
document.write(x.nodeValue);
xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "Default2.aspx", false);
xmlHttp.send(xmlDoc);
}
</script>
</div>
</form>
</body>
</html>
后台;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument dom = new XmlDocument();
dom.Load(Request.InputStream);
dom.Save(Server.MapPath("books.xml"));
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询