一、WebService.asmx:
  处理业务数据,在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>
标签:
Jquery,Ajax学习

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com