Jquery Ajax Learning Instance 4 sends a request to WebService, returning an asynchronous call to an entity object _jquery

Source: Internet
Author: User
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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.