JQuery calls ASP. NET's WebService

Source: Internet
Author: User

1. No parameter call
$ (Document). ready (function (){
$ ('# Button1'). click (function (){
$. Ajax ({
Type: "POST", // WebService access request using Post
ContentType: "application/json", // WebService returns the Json type
Url: "../WebService. asmx/HelloWorld", // address and method name combination for WebService call --- WsURL/method name
Data: "{}", // here is the parameter to be passed, in the format of data: "{paraName: paraValue}", as shown below
DataType: 'json ',
Success: function (result) {// callback function, result, Return Value

Alert (result. d );
}
});

});

});

2. Call with Parameters

$ (Document). ready (function (){
$ ('# Button1'). click (function (){
$. Ajax ({
Type: "POST", // WebService access request using Post
ContentType: "application/json", // WebService returns the Json type
Url: "../WebService. asmx/HelloWorld", // address and method name combination for WebService call --- WsURL/method name
Data: "{userName: 'alpha '}",
DataType: 'json ',
Success: function (result) {// callback function, result, Return Value

Alert (result. d );
}
});

});

});

3. Return compound type

$ (Document). ready (function (){
$ ('# Button1'). click (function (){
$. Ajax ({
Type: "POST", // WebService access request using Post
ContentType: "application/json", // WebService returns the Json type
Url: "../WebService. asmx/GetClass", // a combination of WebService address and method name --- WsURL/method name
Data :"{}",
DataType: 'json ',
Success: function (result) {// callback function, result, Return Value

Alert (result. d ["StuName"]);
}
});

});

});

4. Returns a generic set.

$ (Document). ready (function (){
$ ('# Button1'). click (function (){
$. Ajax ({
Type: "POST", // WebService access request using Post
ContentType: "application/json", // WebService returns the Json type
Url: "../WebService. asmx/GetList", // a combination of WebService address and method name --- WsURL/method name
Data :"{}",
DataType: 'json ',
Success: function (result) {// callback function, result, Return Value

$ (Result. d). each (function (){
$ ("# Result"). append (this ["Id"] + "" + this ["StuName"] + "<br/> ");
});

}
});

});

});

5. Return DataSet (xml format)

$ (Document). ready (function (){
$ ('# Button1'). click (function (){
$. Ajax ({
Type: "POST", // WebService access request using Post
Url: "../WebService. asmx/GetDataSet", // address and method name combination for WebService call --- WsURL/method name
Data :"{}",
DataType: "xml ",
Success: function (result) {// callback function, result, Return Value

$ (Result). find ("Table1"). each (function (){
$ ('# Result '). append ($ (this ). find ("Id "). text () + "" + $ (this ). find ("Name "). text () + "<br/> ");
});

}
});

});

});

 

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.