WebForm1.aspx
前台:
<script language="javascript">
function load(state)
{
var drp2 = document.getElementById("DropDownList2");
for(var i=0;i<=drp2.options.length-1;i++)
{
//drp2.remove(i);
drp2.innerText ="";
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP"); //发送请求
var oDoc = new ActiveXObject("MSXML2.DOMDocument"); //响应结果
var state=document.getElementById("DropDownList1").value;
oHttpReq.open("post","webform2.aspx?state="+state, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
// items = oDoc.selectNodes("//CITY/Table");
items = oDoc.selectNodes("//address/Table");
for (var item = items.nextNode();item;item = items.nextNode())
{
var city = item.selectSingleNode("//address").nodeTypedValue;
var newOption = document.createElement("OPTION");
newOption.text = city;
newOption.value = city;
drp2.options.add(newOption);
}
}
</script>
后台:
if(!IsPostBack)
{
SqlConnection con = new SqlConnection("packet size=4096;user id=sa;pwd=.............");
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM povince",con);
DataSet ds = new DataSet("State");
da.Fill(ds);
this.DropDownList1.DataSource = ds.Tables[0];
this.DropDownList1.DataTextField = "province";
this.DropDownList1.DataValueField = "provinceID";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange","load()");
}WebForm2.aspx:
if(this.Request["state"]!=null)
{
string state = this.Request["state"].ToString();
SqlConnection con = new SqlConnection("packet size=4096;user id=sa;pwd=clsoft;data source=220.201.132.54;persist security info=False;initial catalog=cl1");
SqlDataAdapter da = new SqlDataAdapter("select city,cityid from city where father = '"+state+"'",con);
DataSet ds = new DataSet("address");
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();
}
我觉得好象是xml编码的问题,可是不足道怎么改,请各位指点
前台:
<script language="javascript">
function load(state)
{
var drp2 = document.getElementById("DropDownList2");
for(var i=0;i<=drp2.options.length-1;i++)
{
//drp2.remove(i);
drp2.innerText ="";
}
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP"); //发送请求
var oDoc = new ActiveXObject("MSXML2.DOMDocument"); //响应结果
var state=document.getElementById("DropDownList1").value;
oHttpReq.open("post","webform2.aspx?state="+state, false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
// items = oDoc.selectNodes("//CITY/Table");
items = oDoc.selectNodes("//address/Table");
for (var item = items.nextNode();item;item = items.nextNode())
{
var city = item.selectSingleNode("//address").nodeTypedValue;
var newOption = document.createElement("OPTION");
newOption.text = city;
newOption.value = city;
drp2.options.add(newOption);
}
}
</script>
后台:
if(!IsPostBack)
{
SqlConnection con = new SqlConnection("packet size=4096;user id=sa;pwd=.............");
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM povince",con);
DataSet ds = new DataSet("State");
da.Fill(ds);
this.DropDownList1.DataSource = ds.Tables[0];
this.DropDownList1.DataTextField = "province";
this.DropDownList1.DataValueField = "provinceID";
this.DropDownList1.DataBind();
this.DropDownList1.Attributes.Add("onchange","load()");
}WebForm2.aspx:
if(this.Request["state"]!=null)
{
string state = this.Request["state"].ToString();
SqlConnection con = new SqlConnection("packet size=4096;user id=sa;pwd=clsoft;data source=220.201.132.54;persist security info=False;initial catalog=cl1");
SqlDataAdapter da = new SqlDataAdapter("select city,cityid from city where father = '"+state+"'",con);
DataSet ds = new DataSet("address");
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();
}
我觉得好象是xml编码的问题,可是不足道怎么改,请各位指点
---------
改成
System.Text.Encoding.GetEncoding("gb2312")
试试
或者把你的webconfig改一下
把utf8改成gb2312
result = oHttpReq.responseText;在这里还是乱码, result的结果还是乱吗
<address>
<Table>
<city>?Ͻ?</city>
<cityid>110100</cityid>
</Table>
<Table>
<city>?</city>
<cityid>110200</cityid>
</Table>
</address>
不知道为什么没有<?xml version="1.0" encoding="gb2312"?>它呢?
我改web.config后运行出错
<globalization
requestEncoding="gb2312"
responseEncoding="gb2312"
/>
http://www.vpart.net/google.htm说明在:
http://blog.csdn.net/banmuhuangci