Calling Accessing Web Services/Web methods Using JQuery
Introduction:
In this article,i am going to explain about, how to call a Web service web method using Jquery.
Main:
The below attribute allows us to access the web method using client side programming,
[System.Web.Script.Services.ScriptService]
function WebService()
{
$.ajax({
type: "POST", //Method
url: "Add.asmx/Addnumbers", //Webservice page/Web method
data: "{int a,int b}", //Parameters list
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
}
function OnSuccess(data, status)
{
Alert(data.d);
}
function OnError(request, status, error)
{
Alert(request.statusText);
}
[System.Web.Script.Services.ScriptService] function WebService() { $.ajax({ type: "POST", //Method url: "Add.asmx/Addnumbers", //Webservice page/Web method data: "{int a,int b}", //Parameters list contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, error: OnError }); } function OnSuccess(data, status) { Alert(data.d); } function OnError(request, status, error) { Alert(request.statusText); } |
Conclusion:
Hope this helps,
Happy Coding.