大家帮忙看一下.如何读取返回的xml 数据

qiuqingpo 2009-02-28 09:04:25

<html>
<head>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(str){
createXMLHttpRequest();
try{
//var url="update.aspx?q=";
//url=url+encodeURIComponent(str);

xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET","update.aspx?q="+decodeURIComponent(str), true);
xmlHttp.send(null);
}catch(err){
alert(err.message);
} }
function handleStateChange(){
if(xmlHttp.readyState == 4){
if (xmlHttp.status == 200 || xmlHttp.status == 0){
// 取得XML的DOM对象
var xmlDOM = xmlHttp.responseXML;
// 取得XML文档的根
var root = xmlDOM.documentElement;
try
{
// 取得<info>结果
var info = root.getElementsByTagName('name');

// 显示返回结果
var aa=document.getElementById("name");
aa.innerHTML=info[0].firstChild.data;
alert("responseXML's value: " + info[0].firstChild.data);

}catch(exception)
{
}
}
}
}
</script>
</head>
<body>
<form action="">
<label>选择客户:
<select name="customers" onchange="startRequest(this.value);">
<option value="qqqii">qqqii</option>
<option value="qiqingpoi">qiqingpoi</option>
<option value="qiuqingpo@126.com">qiuqingpo@126.com</option>
</select></label>
</form>

<b><span id="name"></span></b><br />
<span id="discription"></span><br />
</body>
</html>


update.aspx代码

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="c#" runat="server">
void Page_Load(object sender,EventArgs e)
{
string str1 = Server.UrlDecode(Request .QueryString ["q"].ToString());
OleDbConnection cn = new OleDbConnection("provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("update+xml.mdb"));
string sql = "select name,discription from test where name='"+str1+"'";
OleDbCommand cmd=new OleDbCommand(sql,cn);
cn.Open();
OleDbDataReader dr=cmd.ExecuteReader();
try
{
while (dr.Read())
{
Response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>");
Response.Write("<company>");
Response.Write("<name>" + dr.GetValue(0) + "</name>");
Response.Write("<discription>" + dr.GetValue(1) + "</discription>");
Response.Write("</company>");
}
}
finally
{
cn.Close();
}
}
</script>

数据库为access数据库.
表名test 字段名:name ,discription
可是就是没有结果呀???
...全文
70 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

52,782

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧