您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

JQuery中ajax方法访问web服务实例_jquery

2025/11/18 16:50:18发布28次查看
本文实例讲述了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,//注明 返回jsoncontenttype: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程序设计有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product