相思资源网 Design By www.200059.com
一、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>
处理业务数据,在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学习
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无Jquery Ajax学习实例4 向WebService发出请求,返回实体对象的异步调用的评论...