会员
众包
新闻
博问
闪存
云市场
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
HuaZi4995 工 作 笔 记
路漫漫其修远兮!!!
博客园
首页
新随笔
联系
订阅
管理
利用webservice实现省、市的无刷新
这个是一个webservice方法,返回一个DATASET
[WebMethod(Description
=
"
得到市
"
)]
public
DataSet GetChengShi(
string
strType)
{
string
strcon
=
"
server=(local);database=lsa_anqiu;uid=sa;pwd=sundun
"
;
SqlConnection conn
=
new
SqlConnection(strcon);
string
strSelect
=
string
.Format(
"
select chengshi from chengshi where shengfen='{0}'
"
,strType);
SqlDataAdapter da
=
new
SqlDataAdapter(strSelect,conn);
DataSet ds
=
new
DataSet();
da.Fill(ds);
return
ds;
}
//
得到城市,webservice
function
GetChengShiJ(drp)
{
//
选中的值(省)
var
strS
=
window.Form1.drpS.value;
//
如果市有值则清空
var
objList
=
document.getElementById(
"
drpC
"
);
if
(objList.options.length
!=
0
)
{
for
(
var
iDel
=
0
;iDel
<
objList.options.length;iDel
++
)
{
objList.options[iDel]
=
null
;
objList.options.remove(iDel);
iDel
--
;
}
}
//
增加一空列
objList.add(document.createElement(
"
OPTION
"
));
objList.options[
0
].text
=
""
;
objList.options[
0
].value
=
""
;
var
xmlData
=
new
ActiveXObject(
"
Msxml.DOMDocument
"
);
xmlData.async
=
false
//
调用webservice,返回一个dataset
var
vstr
=
"
Service1.asmx/GetChengShi?strType=
"
+
strS
xmlData.load( vstr);
xmlValue
=
xmlData.getElementsByTagName(
"
chengshi
"
);
xmlText
=
xmlData.getElementsByTagName(
"
chengshi
"
);
for
(
var
i
=
0
; i
<
xmlValue.length; i
++
)
{
objList.add(document.createElement(
"
OPTION
"
));
objList.options[i
+
1
].text
=
xmlText.item(i).text;
objList.options[i
+
1
].value
=
xmlValue.item(i).text;
}
}
<
SELECT
id
="drpS"
runat
="server"
onchange
="GetChengShiJ(this);"
>
<
OPTION
selected value
="广东"
>
广东
</
OPTION
>
<
OPTION
value
="湖北"
>
湖北
</
OPTION
>
<
OPTION
value
="湖南"
>
湖南
</
OPTION
>
<
OPTION
value
=""
></
OPTION
>
</
SELECT
><
SELECT
id
="drpC"
runat
="server"
>
<
OPTION
selected
></
OPTION
>
</
SELECT
>
注意,JAVASCRIPT调用WEBSERVICE需要在WEB。CONFIG里设置
<
webServices
>
<
protocols
>
<
add
name
="HttpSoap"
/>
<
add
name
="HttpPost"
/>
<
add
name
="HttpGet"
/>
<
add
name
="Documentation"
/>
</
protocols
>
</
webServices
>
posted on
2006-12-05 17:50
huazi4995
阅读(
378
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部