当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js操作Xml(向服务器发送Xml,处理服务器返回的Xml)(IE下有效)

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 js操作Xml(向服务器发送Xml,处理服务器返回的Xml)(IE下有效)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 338 ::
收藏到网摘: n/a

js操作Xml(向服务器发送Xml,处理服务器返回的Xml)(暂只IE下有效) 前台:
复制代码 代码如下:

<!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();
}
}