1. No parameter call $ (document ). ready (function () {$ (& amp; #39 ;# Button1 & amp; #39 ;). click (function () {$. ajax ({type: & quot; POST & quot;, // access WebService using Post to request contentType: & quot; appli
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"] +"
");
});
}
});
});
});
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 () +"
");
});
}
});
});
});