1. WebService. asmx:
Process business data and generate the Person Entity Data in the GetPerson Method for JqueryRequest. aspx to call. The Code is as follows:
[WebMethod]
Public Person GetPerson (string name, int age, string address)
{
Person p = new Person ()
{
Name = name,
Age = age,
Address = address
};
Return p;
}
Ii. Person. cs entity class:
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 ;}
}
}
Iii. AjaxRequest. aspx
Click the button to request the GetPerson (string name, int age, string address) method of WebService. asmx to obtain the Person object data. The Code is as follows:
<Script type = "text/javascript" language = "javascript">
Function BtnPerson_Click (){
$. Ajax ({
Url: "WebService. asmx/GetPerson ",
Data: {name: "Windy", age: 18, address: "Liehuo. Net 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 );
}
}); // Bkjia.com
}
</Script>