ajax解析XML文档
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PIX_Test.aspx.cs" Inherits="ZK_PIX.PIX_Test" %>
<!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 runat="server">
<title>无标题页</title>
<script type="text/javascript" language="javascript">
var XMLHttpReq = false;
var uname;
var psw;
//创建XMLHttpRequest对象
function createXMLHttpRequest() {
if (window.XMLHttpRequest) { //Mozilla 浏览器
XMLHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE浏览器
try {
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { }
}
}
}
//发送请求函数
function sendRequest() {
createXMLHttpRequest();
var xml = createXML();
window.alert(xml);
XMLHttpReq.open("POST", "/PIX_RegistPatient.aspx", false);
XMLHttpReq.onreadystatechange = processResponse; //指定响应函数
XMLHttpReq.setRequestHeader("Content-Type", "application/x-www-form- urlencoded");
XMLHttpReq.send(xml); // 发送请求
}
// 处理返回信息函数
function processResponse() {
if (XMLHttpReq.readyState == 4) { // 判断对象状态
if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息
var res = XMLHttpReq.responseText;
window.alert(res);
} else { //页面不正常
window.alert("您所请求的页面有异常。");
}
}
}
//创建XML
function createXML() {
var xml = "<?xml version=\"1.0\" encoding=\"gbk\" ?><Patient><domain code=\"010101\" LPID=\"12345\" Flag=\"0\" /><name>测试</name><gender>男</gender><birth>19730303</birth><blood>B</blood><birthplace>0405</birthplace><code name=\"军官证\" type=\"0\"/><addr /><hp /><wp /><email /><mobile /></Patient>";
return xml;
}
</script>
</head>
<body onload="sendRequest()">
<form id="form1" runat="server">
<div>
</div>
</form>
</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 runat="server">
<title>无标题页</title>
<script type="text/javascript" language="javascript">
var XMLHttpReq = false;
var uname;
var psw;
//创建XMLHttpRequest对象
function createXMLHttpRequest() {
if (window.XMLHttpRequest) { //Mozilla 浏览器
XMLHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IE浏览器
try {
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { }
}
}
}
//发送请求函数
function sendRequest() {
createXMLHttpRequest();
var xml = createXML();
window.alert(xml);
XMLHttpReq.open("POST", "/PIX_RegistPatient.aspx", false);
XMLHttpReq.onreadystatechange = processResponse; //指定响应函数
XMLHttpReq.setRequestHeader("Content-Type", "application/x-www-form- urlencoded");
XMLHttpReq.send(xml); // 发送请求
}
// 处理返回信息函数
function processResponse() {
if (XMLHttpReq.readyState == 4) { // 判断对象状态
if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息
var res = XMLHttpReq.responseText;
window.alert(res);
} else { //页面不正常
window.alert("您所请求的页面有异常。");
}
}
}
//创建XML
function createXML() {
var xml = "<?xml version=\"1.0\" encoding=\"gbk\" ?><Patient><domain code=\"010101\" LPID=\"12345\" Flag=\"0\" /><name>测试</name><gender>男</gender><birth>19730303</birth><blood>B</blood><birthplace>0405</birthplace><code name=\"军官证\" type=\"0\"/><addr /><hp /><wp /><email /><mobile /></Patient>";
return xml;
}
</script>
</head>
<body onload="sendRequest()">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
protected void Page_Load(object sender, EventArgs e)
{
CheckPage.SetHeader();
StreamReader reader = new StreamReader(Request.InputStream);
String xml = reader.ReadToEnd();
}
{
CheckPage.SetHeader();
StreamReader reader = new StreamReader(Request.InputStream);
String xml = reader.ReadToEnd();
}