前台:
复制代码 代码如下:
<!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文件然后发向服务器</title>
<script type="text/javascript"><!--
var xmlHttp = null;
function f(){
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.load("xmlfile.xml");//只改了这里,原来是loadXML("");
sendXml( xmlDoc,'Default.aspx');
}
//向服务器发送Xml文档
function sendXml(xmlDoc,serverURL){
xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP.3.0");
var strDoc;
if (typeof(xmlDoc) == "object")//这里的判断是需要的.这里仍然需要加个xml后缀
strDoc = xmlDoc.xml;
else
strDoc = xmlDoc;
xmlHttp.open ("POST","Default.aspx" ,true);
xmlHttp.onreadystatechange=getData;
xmlHttp.send(strDoc);
}
function getData(){
if (xmlHttp.readyState==4)
{
var strxml=xmlHttp.responseText;
//这里接受服务器传来的Xml文档,转化成xml文档.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.loadXML(strxml);
//alert(xmlDoc.xml);
var singleNode = xmlDoc.selectSingleNode("/root/person[gender='male']");//这里的值需要加引号
alert(singleNode.text);
}
}
// --></script>
</head>
<body>
<input type="button" onclick="f();" value="request" />
</body>
</html>
<!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文件然后发向服务器</title>
<script type="text/javascript"><!--
var xmlHttp = null;
function f(){
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.load("xmlfile.xml");//只改了这里,原来是loadXML("");
sendXml( xmlDoc,'Default.aspx');
}
//向服务器发送Xml文档
function sendXml(xmlDoc,serverURL){
xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP.3.0");
var strDoc;
if (typeof(xmlDoc) == "object")//这里的判断是需要的.这里仍然需要加个xml后缀
strDoc = xmlDoc.xml;
else
strDoc = xmlDoc;
xmlHttp.open ("POST","Default.aspx" ,true);
xmlHttp.onreadystatechange=getData;
xmlHttp.send(strDoc);
}
function getData(){
if (xmlHttp.readyState==4)
{
var strxml=xmlHttp.responseText;
//这里接受服务器传来的Xml文档,转化成xml文档.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.loadXML(strxml);
//alert(xmlDoc.xml);
var singleNode = xmlDoc.selectSingleNode("/root/person[gender='male']");//这里的值需要加引号
alert(singleNode.text);
}
}
// --></script>
</head>
<body>
<input type="button" onclick="f();" value="request" />
</body>
</html>
Ajax
复制代码 代码如下:
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
xmldoc.Save(Server.MapPath("~"+"/hello.xml"));
Response.Write(xmldoc.InnerXml);//返回修改后的Xml文档
Response.End();
}
}
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
xmldoc.Save(Server.MapPath("~"+"/hello.xml"));
Response.Write(xmldoc.InnerXml);//返回修改后的Xml文档
Response.End();
}
}
Xml文档:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<person id="1">
<name>tree</name>
<gender>male</gender>
</person>
</root>
复制代码 代码如下:
<!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文件然后发向服务器</title>
<script type="text/javascript"><!--
var xmlHttp = null;
function f(){
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.load("xmlfile.xml");//只改了这里,原来是loadXML("");
sendXml( xmlDoc,'Default.aspx');
}
//向服务器发送Xml文档
function sendXml(xmlDoc,serverURL){
xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP.3.0");
var strDoc;
if (typeof(xmlDoc) == "object")//这里的判断是需要的.这里仍然需要加个xml后缀
strDoc = xmlDoc.xml;
else
strDoc = xmlDoc;
xmlHttp.open ("POST","Default.aspx" ,true);
xmlHttp.onreadystatechange=getData;
xmlHttp.send(strDoc);
}
function getData(){
if (xmlHttp.readyState==4)
{
var strxml=xmlHttp.responseText;
//这里接受服务器传来的Xml文档,转化成xml文档.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.loadXML(strxml);
//alert(xmlDoc.xml);
var singleNode = xmlDoc.selectSingleNode("/root/person[gender='male']");//这里的值需要加引号
alert(singleNode.text);
}
}
// --></script>
</head>
<body>
<input type="button" onclick="f();" value="request" />
</body>
</html>
<!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文件然后发向服务器</title>
<script type="text/javascript"><!--
var xmlHttp = null;
function f(){
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.load("xmlfile.xml");//只改了这里,原来是loadXML("");
sendXml( xmlDoc,'Default.aspx');
}
//向服务器发送Xml文档
function sendXml(xmlDoc,serverURL){
xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP.3.0");
var strDoc;
if (typeof(xmlDoc) == "object")//这里的判断是需要的.这里仍然需要加个xml后缀
strDoc = xmlDoc.xml;
else
strDoc = xmlDoc;
xmlHttp.open ("POST","Default.aspx" ,true);
xmlHttp.onreadystatechange=getData;
xmlHttp.send(strDoc);
}
function getData(){
if (xmlHttp.readyState==4)
{
var strxml=xmlHttp.responseText;
//这里接受服务器传来的Xml文档,转化成xml文档.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async = false;
xmlDoc.loadXML(strxml);
//alert(xmlDoc.xml);
var singleNode = xmlDoc.selectSingleNode("/root/person[gender='male']");//这里的值需要加引号
alert(singleNode.text);
}
}
// --></script>
</head>
<body>
<input type="button" onclick="f();" value="request" />
</body>
</html>
Ajax
复制代码 代码如下:
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
xmldoc.Save(Server.MapPath("~"+"/hello.xml"));
Response.Write(xmldoc.InnerXml);//返回修改后的Xml文档
Response.End();
}
}
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
xmldoc.Save(Server.MapPath("~"+"/hello.xml"));
Response.Write(xmldoc.InnerXml);//返回修改后的Xml文档
Response.End();
}
}
Xml文档:
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<person id="1">
<name>tree</name>
<gender>male</gender>
</person>
</root>
标签:
js,xml,服务器
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“js装载xml文件然后发向服务器的实现代码”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。