本文实例讲述了JQuery中ajax方法访问web服务。分享给大家供大家参考。具体分析如下:
说明: ArrayList 中 存为对象CollegeDepartInfo 其属性为:stirng CollegeDepartTitle 和 int CollegeDepartId 在javascript中 ddlDepart.options[ddlDepart.length]=new Option(n.CollegeDepartTitle,n.CollegeDepartId); Option的参数就是依据他们的。 最后重要的是: 类上方添加的 [ScriptService] 必须添加,否则ajax无法调用WebService
jquery代码部分:
$.ajax({ type: "POST", //注明 返回Json contentType:"application/json;utf-8", //CollegeDepartWebServices.asmx web服务名 /GetCollegeDepart 方法名 url:"CollegeDepartWebServices.asmx/GetCollegeDepart", //strDepartId 参数名称 collegeId 参数值 data:"{strDepartId:"+collegeId+"}", dataType:"json", success:function(result){ var json=null try { if(result) { //因为返回的是ArrayList 所以循环取出其中的值 $.each(result, function(i, n){ //ddlDepart 为下来菜单。循环的向下拉菜单中添加新的选项 ddlDepart.options[ddlDepart.length]=new Option(n.CollegeDepartTitle,n.CollegeDepartId); }); } } catch(e) { alert("错误"+e.message); return; } }, error:function(data) { alert(data.status+"> "+data.statusText); } });
CollegeDepartWebServices.asmx.cs部分:
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class CollegeDepartWebServices : System.Web.Services.WebService { public CollegeDepartWebServices() { //如果使用设计的组件,请取消注释以下行 //InitializeComponent(); } [WebMethod] [System.Xml.Serialization.XmlInclude(typeof(CollegeDepartInfo))] public ArrayList GetCollegeDepart(string strDepartId) { CollegeDepartBL.FlushCollegeDepartCache(); if (string.IsNullOrEmpty(strDepartId)) return null; ArrayList myList = CollegeDepartBL.GetCollegeDepartListByCollegeID(int.Parse(strDepartId)); return myList; } }
希望本文所述对大家的jquery程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月27日
2024年09月27日
- 许美静.1999-快乐无罪【上华】【WAV+CUE】
- 群星.2024-Jambo.Medley(BEYOND40周年·致敬2)【Kinns】【FLAC分轨】
- 林翠萍.1991-舞曲世界2辑【星河】【WAV+CUE】
- 关智斌.2007-In.Progress【英皇娱乐】【FLAC分轨】
- 群星.2000-电影主题曲原声带·琼瑶的世界【歌林】【WAV+CUE】
- 范世錡.2024-錡妙夜(EP)【天娱传媒】【FLAC分轨】
- 谭咏麟.2000-魅力千禧演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 纯音入心系列纯音乐《器乐古筝》1CD[MP3][239MB]
- 纯音入心系列纯音乐《华夏民乐之古筝篇》1CD[MP3][192MB]
- 纯音入心系列纯音乐《中央民族乐团-古筝传奇》1CD[MP3][253.1MB]
- 江玲.1989-这样你才爱我,是吗?【新作有声】【WAV+CUE】
- 郭美美.2010-我是郭美美【华纳】【WAV+CUE】
- 黄心懋1991-轻忧郁【滚石】【WAV+CUE】
- 群星.2000-大地金曲世纪回顾2CD【大地】【WAV+CUE】
- 王菲.1996-浮躁(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】