1. webservice end
Using System;
Using System. Collections. Generic;
Using System. Web;
Using System. Web. Services;
Using System. Configuration;
Using System. Data. SqlClient;
Using System. Data;
/// <Summary>
/// Summary of WebService
/// </Summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
Public class WebService: System. Web. Services. WebService {
Public WebService (){
// If you use the designed component, uncomment the following line
// InitializeComponent ();
}
[WebMethod]
Public string HelloWorld (string userName ){
Return "Hello World" + userName;
}
}
2. Client
<Script src = "js/jquery. js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("# Button1"). click (function (){
Try {
$. Ajax ({
Type: "POST", // WebService access request using post
ContentType: "application/json; UTF-8", // WebService returns the json type
Url: "http: // localhost: 8321/WebService. asmx/HelloWorld", // address and method name combination of WebService call
Data: "{userName: 'jodie '}", // here is the parameter to be passed, in the format of data: "{paraName: paraValue }"
DataType: "json ",
Success: function (result ){
$ ("# Result" example .html (result. d );
Alert (result. d );
}
})
}
Catch (ex ){
Alert (ex );
}
})
})
</Script>
This article