利用webservice实现省、市的无刷新

这个是一个webservice方法,返回一个DATASET

None.gif [WebMethod(Description = " 得到市 " )]
None.gif        
public  DataSet GetChengShi( string   strType)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
string strcon="server=(local);database=lsa_anqiu;uid=sa;pwd=sundun";
InBlock.gif            SqlConnection conn
=new SqlConnection(strcon);
InBlock.gif
InBlock.gif            
string strSelect=string.Format("select  chengshi from chengshi where shengfen='{0}' ",strType);
InBlock.gif    
InBlock.gif            SqlDataAdapter da
=new SqlDataAdapter(strSelect,conn);
InBlock.gif            DataSet ds
=new DataSet();
InBlock.gif            da.Fill(ds);
InBlock.gif
InBlock.gif            
return ds;
InBlock.gif
ExpandedBlockEnd.gif        }


None.gif // 得到城市,webservice
None.gif
     function  GetChengShiJ(drp)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif    
InBlock.gif            
//选中的值(省)
InBlock.gif
            var strS=window.Form1.drpS.value;
InBlock.gif            
//如果市有值则清空
InBlock.gif
            var objList = document.getElementById("drpC");
InBlock.gif            
if (objList.options.length !=0
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
for (var iDel=0;iDel<objList.options.length;iDel++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    objList.options[iDel]
=null ;
InBlock.gif                    objList.options.remove(iDel);
InBlock.gif                    iDel
--;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
//增加一空列
InBlock.gif
            objList.add(document.createElement("OPTION"));
InBlock.gif            objList.options[
0].text = "";
InBlock.gif            objList.options[
0].value = "";
InBlock.gif            
InBlock.gif            
InBlock.gif            
var xmlData = new ActiveXObject("Msxml.DOMDocument");
InBlock.gif            xmlData.async 
= false
InBlock.gif            
//调用webservice,返回一个dataset
InBlock.gif
            var vstr="Service1.asmx/GetChengShi?strType="+strS
InBlock.gif            xmlData.load( vstr);
InBlock.gif            
InBlock.gif            xmlValue 
= xmlData.getElementsByTagName("chengshi");
InBlock.gif            xmlText 
= xmlData.getElementsByTagName("chengshi");
InBlock.gif
InBlock.gif            
InBlock.gif            
for (var i=0; i<xmlValue.length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                objList.add(document.createElement(
"OPTION"));
InBlock.gif                objList.options[i
+1].text = xmlText.item(i).text;
InBlock.gif                objList.options[i
+1].value = xmlValue.item(i).text;
ExpandedSubBlockEnd.gif            }

InBlock.gif                        
ExpandedBlockEnd.gif    }


None.gif < SELECT  id ="drpS"  runat ="server"  onchange ="GetChengShiJ(this);" >
None.gif                            
< OPTION  selected value ="广东" > 广东 </ OPTION >
None.gif                            
< OPTION  value ="湖北" > 湖北 </ OPTION >
None.gif                            
< OPTION  value ="湖南" > 湖南 </ OPTION >
None.gif                            
< OPTION  value ="" ></ OPTION >
None.gif                        
</ SELECT >< SELECT  id ="drpC"  runat ="server" >
None.gif                            
< OPTION  selected ></ OPTION >
None.gif                        
</ SELECT >

注意,JAVASCRIPT调用WEBSERVICE需要在WEB。CONFIG里设置
None.gif < webServices >
None.gif      
< protocols >
None.gif        
< add  name ="HttpSoap"   />
None.gif        
< add  name ="HttpPost"   />
None.gif        
< add  name ="HttpGet"   />
None.gif        
< add  name ="Documentation"   />
None.gif      
</ protocols >
None.gif    
</ webServices >

转载于:https://www.cnblogs.com/huazi4995/archive/2006/12/05/583111.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值