会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
笔记本
......
博客园
首页
新随笔
联系
管理
订阅
实现无刷新(script访问)
......
private
void
Page_Load(
object
sender, System.EventArgs e)
{
if
(
this
.Request[
"
state
"
]
!=
null
)
{
string
state
=
this
.Request[
"
state
"
].ToString();
SqlConnection con
=
new
SqlConnection(
"
server=localhost;database=pubs;uid=sa;pwd=sa;
"
);
SqlDataAdapter da
=
new
SqlDataAdapter(
"
select city from authors where state = '
"
+
state
+
"
'
"
,con);
DataSet ds
=
new
DataSet(
"authors
"
);
da.Fill(ds);
//
以下是创建XML格式输出
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如下:
<
NewDataSet
>
<
authors
>
<
city
>
wuhan
</
city
>
</
authors
>
</
NewDataSet
>
<
script
>
function
load()
{
var
oHttpReq
=
new
ActiveXObject(
"
MSXML2.XMLHTTP
"
);
var
oDoc
=
new
ActiveXObject(
"
MSXML2.DOMDocument
"
);
//
打开某文件
oHttpReq.open(
"
POST
"
,
"
webform6.aspx?state=
"
+
state,
false
);
oHttpReq.send(
""
);
result
=
oHttpReq.responseText;
//
读取XML
oDoc.loadXML(result);
items
=
oDoc.selectNodes(
"
//authors
"
);
for
(
var
item
=
items.nextNode(); item; item
=
items.nextNode())
{
var
city
=
item.selectSingleNode(
"
//city
"
).nodeTypedValue;
xx.value = city;
}
}
</
script
>
posted @
2004-10-13 13:16
小Dan
阅读(
781
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告