Jquery Ajax学习实例4 向WebService发出请求,返回实体对象的异步调用
一、WebService.asmx:
处理业务数据,在GetPerson方法中产生Person实体类数据,供JqueryRequest.aspx调用,代码如下:
二、Person.cs实体类:
三、AjaxRequest.aspx
通过点击按钮来请求WebService.asmx的GetPerson(string name, int age, string address)方法,获取Person实体数据。代码如下:
处理业务数据,在GetPerson方法中产生Person实体类数据,供JqueryRequest.aspx调用,代码如下:
代码如下:
[WebMethod] public Person GetPerson(string name, int age, string address) { Person p = new Person() { Name = name, Age = age, Address = address }; return p; }
二、Person.cs实体类:
代码如下:
public class Person { private string _name; public string Name { get { return _name; } set { _name = value; } } private int _age; public int Age { get { return _age; } set { _age = value; } } private string _address; public string Address { get { return _address; } set { _address = value; } } }
三、AjaxRequest.aspx
通过点击按钮来请求WebService.asmx的GetPerson(string name, int age, string address)方法,获取Person实体数据。代码如下:
代码如下:
<script type="text/javascript" language="javascript"> function BtnPerson_Click() { $.ajax({ url: "WebService.asmx/GetPerson", data: { name: "Windy", age: 18, address: "Shanghai China" }, type: "post", success: function(data, status) { var obj = $(data); var name = obj.find("Name").text(); var age = obj.find("Age").text(); var address = obj.find("Address").text(); alert("Name:" + name + " Age:" + age + " Address:" + address); } }); } </script>
相关推荐
TONIYH 2020-07-22
83510998 2020-07-18
wcqwcq 2020-06-26
delmarks 2020-06-14
ppsurcao 2020-06-14
tthappyer 2020-06-07
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03