First, Webservice.asmx:
Processing business data, generating the person entity class data in the Getperson method for jqueryrequest.aspx invocation, the code is as follows:
Copy Code code as follows:
[WebMethod]
Public person Getperson (string name, int age, string address)
{
Person p = new person ()
{
Name = name,
Age = Age,
Address = Address
};
return p;
}
Second, Person.cs entity class:
Copy Code code as follows:
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;}
}
}
Third, ajaxrequest.aspx
Request Webservice.asmx's Getperson (string name, int age, string address) method to get the person Entity data by clicking on the button. The code is as follows:
Copy Code code as follows:
<script type= "Text/javascript" language= "javascript" >
function Btnperson_click () {
$.ajax ({
URL: "Webservice.asmx/getperson",
Data: {name: "Windy", age:18, Address: "Shanghai"},
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>