Chinaunix首页 | 论坛 | 博客
  • 博客访问: 593466
  • 博文数量: 64
  • 博客积分: 7040
  • 博客等级: 少将
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-09 20:38
文章存档

2012年(1)

2011年(8)

2010年(16)

2009年(18)

2008年(21)

我的朋友

分类:

2008-09-26 08:21:30

<script language="javascript">
   function load(state)
   {
    var drp2 = document.getElementById("SearchType1");
    while(drp2.length!=0)
    {
        drp2.remove(0);
    }
    var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP"); //发送请求
    var oDoc = new ActiveXObject("MSXML2.DOMDocument"); //响应结果
    var state=document.getElementById("SearchType");
    oHttpReq.open("post","temp.aspx?state="+state.options[state.selectedIndex].value,false);
    oHttpReq.send("");
    result = oHttpReq.responseText;
    oDoc.loadXML(result); 
   // items = oDoc.selectNodes("//CITY/Table");
       var items = oDoc.selectNodes("//NewDataSet/type");
   for (var item = items.nextNode();item;item = items.nextNode())
   { 
    var city = item.selectSingleNode("name").nodeTypedValue;
    var newOption = document.createElement("OPTION"); 
    newOption.text = city; 
    newOption.value = city; 
    drp2.options.add(newOption); 
   }
  </script>

 

SearchType.Attributes.Add("onchange", "load()");

 

这里要注意的是中文传递:首先在Webconfig里面加上下面一句

 

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="zh-CN" uiCulture="zh-CN"/>

 

接着在temp.aspx里面加下下面一句

 

Encoding gb2312 = Encoding.GetEncoding("gb2312");
        Request.ContentEncoding = gb2312;

在这个空间里面using System.Text;

 

OleDbCommand cmd = new OleDbCommand("select name from Type", con);
                    OleDbDataAdapter oda = new OleDbDataAdapter();
                    oda.SelectCommand = cmd;
                    DataSet ds = new DataSet();
                    oda.Fill(ds, "type");
                    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();

阅读(835) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-07-09 10:59:48

真的谢谢你。