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是有数据的

解决方案 »

  1.   

    我找的一个,drpdlstNoFresh.aspx文件内容:<%@ Page language="c#" Codebehind="drpdlstNoFresh.aspx.cs" AutoEventWireup="false" Inherits="localhost.duo.drpdlstNoFresh" %>
    <!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
    }
    }
      

  2.   

    drpdlstnofresh1.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;
    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
    }
    }
      

  3.   

    我用的就是这个方法,但oHttpReq.responseText返回的结果项中子节点没有数据
      

  4.   

    result = oHttpReq.responseText;
    改一下
    result = oHttpReq.responseXML;
      

  5.   

    result = oHttpReq.responseText;
    oDoc.loadXML(result);
    result返回的是xml格式的才可以这样用,不是xml格式的loadXML不会成功的
      

  6.   

    还有一种方法。
    oDoc.load(url);这样也行 不要xmlhttp
      

  7.   

    查看result返回的结果,读出来的只有结构
    <name>
        <Table>
            <title></title>
        </Table>
    </name>
    为什么没有读出数据呢?
      

  8.   

    把你的NodeData1.aspx文件的原码让我看看
      

  9.   

    if(this.Request["id"]!=null)
    {
    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();
    }
      

  10.   

    我对XML不是很了解,请大家帮忙指点
      

  11.   

    问题解决了,是XML编码的问题