使用JQuery中ajax方法访问web服务。
2008-06-25 10:10
791 查看
使用JQuery中ajax方法访问web服务。
1.ajax方法需要填写:
JScript code
----
CollegeDepartWebServices.asmx.cs web服务类
C# code
说明:
ArrayList 中 存为对象CollegeDepartInfo
其属性为:stirng CollegeDepartTitle 和 int CollegeDepartId
在javascript中
ddlDepart.options[ddlDepart.length]=new Option(n.CollegeDepartTitle,n.CollegeDepartId);
Option的参数就是依据他们的。
最后重要的是:
类上方添加的
[ScriptService]
必须添加,否则ajax无法调用WebService
1.ajax方法需要填写:
JScript code
$.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 web服务类
C# code
[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; } }
说明:
ArrayList 中 存为对象CollegeDepartInfo
其属性为:stirng CollegeDepartTitle 和 int CollegeDepartId
在javascript中
ddlDepart.options[ddlDepart.length]=new Option(n.CollegeDepartTitle,n.CollegeDepartId);
Option的参数就是依据他们的。
最后重要的是:
类上方添加的
[ScriptService]
必须添加,否则ajax无法调用WebService
相关文章推荐
- JQuery中ajax方法访问web服务实例
- JQuery中ajax方法访问web服务实例
- asp.net2.0使用jquery.tree及$.ajax调用[WebMethod]方法
- Jquery结合Ajax和Web服务使用三层架构实现无刷新分页
- WebWorks中使用JQuery的getJSON方法进行跨域访问
- 使用jquery的ajax方法调用webservice服务
- Jquery结合Ajax和Web服务使用三层架构实现无刷新分页
- 代码下行Jquery结合Ajax和Web服务使用三层架构实现无刷新分页
- 使用ASP.NET AJAX 从脚本中调用Web 服务的应用方法
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据(转)
- 前端使用Jquery的getJSON方法,后台使用PHP,解决IE和火狐Firefox中存在的跨域ajax请求问题。
- [转]甩掉 ashx/asmx,使用jQuery.ajaxWebService请求WebMethod,Ajax处理更加简练
- 混合使用Azure LB和ILB访问相同web服务(1)
- jQuery.ajax使用方法
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据(转)
- 使用SOAP访问Web服务
- 使用Spring进行远程访问与Web服务
- 使用jquery+json实现ajax的方法
- 使用Apache Axis部署 Web服务时的常见问题及其解决方法
- Asp中使用JQuery的AJAX提交中文乱码解决方法