var oHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
var oDoc = new ActiveXObject("Microsoft.XMLDOM");
oHttpReq.open("POST", "NodeData1.aspx?id="+ClassID, false); //调用读取小类数据的页面,将大类编号值传递过去
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items = oDoc.selectNodes("//NewDataSet/Table/title"); //读取所有请求大类所属小类的名称
alert(items[0]);用alert查看数据是空的,但NodeData1.aspx页面查询后生成的XML是有数据的
var oDoc = new ActiveXObject("Microsoft.XMLDOM");
oHttpReq.open("POST", "NodeData1.aspx?id="+ClassID, false); //调用读取小类数据的页面,将大类编号值传递过去
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items = oDoc.selectNodes("//NewDataSet/Table/title"); //读取所有请求大类所属小类的名称
alert(items[0]);用alert查看数据是空的,但NodeData1.aspx页面查询后生成的XML是有数据的
解决方案 »
- ASP.NET生成失败
- MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)路径问题
- iframe 不起作用?
- 如何去掉<img>在超链接〈a>中出现的边框?
- 各位大哥帮忙了,我用treeview控件,写了一个类,却怎么也显示不出来
- access数据库怎么处理多用户同时访问?
- 请问创建文件夹的代码怎么写啊?
- 一个从列表框中删除选中项的问题,求解决
- odbc查询
- 类似火狐FireBug这样的在客户端恶意修改数据提交的问题如何解决
- 高手进:请教该SQL语句如何写。
- 再次求救!!!!!急啊..谢谢
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>drpdlstNoFresh</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function load(state){
var drp2 = document.getElementById("DropDownList2");
for(var i = 0;i<=drp2.options.length -1;i++){
drp2.remove(i);
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
oHttpReq.open("POST", "drpdlstnofresh1.aspx?state="+state, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
items = oDoc.selectNodes("//CITY/Table");
for (var item = items.nextNode(); item; item = items.nextNode()){
var city = item.selectSingleNode("//city").nodeTypedValue;
var newOption = document.createElement("OPTION");
newOption.text = city;
newOption.value = city;
drp2.options.add(newOption);
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
</form>
</body>
</HTML>drpdlstNoFresh.aspx.cs文件内容:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace localhost.duo
{
/// <summary>
/// drpdlstNoFresh 的摘要说明。
/// </summary>
public class drpdlstNoFresh : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection con = new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=;");
SqlDataAdapter da = new SqlDataAdapter("select state from authors group by state",con);
DataSet ds = new DataSet();
da.Fill(ds);
this.DropDownList1.DataSource=ds;
this.DropDownList1.DataTextField = "State";
this.DropDownList1.DataValueField = "State";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange","load(this.options[this.selectedIndex].innerText)");
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;namespace localhost.duo
{
/// <summary>
/// drpdlstnofresh1 的摘要说明。
/// </summary>
public class drpdlstnofresh1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(this.Request["state"]!=null)
{
string state = this.Request["state"].ToString();
SqlConnection con = new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=;");
SqlDataAdapter da = new SqlDataAdapter("select city from authors where state = '"+state+"'",con);
DataSet ds = new DataSet("CITY");
da.Fill(ds);
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
ds.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
改一下
result = oHttpReq.responseXML;
oDoc.loadXML(result);
result返回的是xml格式的才可以这样用,不是xml格式的loadXML不会成功的
oDoc.load(url);这样也行 不要xmlhttp
<name>
<Table>
<title></title>
</Table>
</name>
为什么没有读出数据呢?
{
string id = this.Request["id"].ToString();
string sql="select title from 目录树表 where parent='"+id+"'";SqlDataAdapter da = new SqlDataAdapter(sql,control.objConnection);
DataSet ds = new DataSet("name");
da.Fill(ds);
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
ds.WriteXml(writer);
writer.Flush();
writer.Close();
Response.End();
}