Example 1: Call Webservice using JQuery AJax (Without Input)



<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>


<h2>Example 1: Call Webservice using JQuery AJax (Without Input)</h2>
<asp:Button ID="btnGetMsg" runat="server" Text="Click Me" OnClientClick="DisplayMessageCall();return false;" /><br />
<asp:Label ID="lblOutput" runat="server" Text=""></asp:Label>

<script type = "text/javascript">
    function DisplayMessageCall() {

        var pageUrl = '<%=ResolveUrl("~/WebService/wsHelloWorld.asmx")%>'

            type: "POST",
            url: pageUrl + "/DisplayMessage",
            data: '{}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccessCall,
            error: OnErrorCall


    function OnSuccessCall(response) {

    function OnErrorCall(response) {
        alert(response.status + " " + response.statusText);



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace HelloWorldJQueryAjax.WebService
    /// <summary>
    /// Summary description for HelloWorld
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    public class HelloWorld : System.Web.Services.WebService

        public string DisplayMessage()
            return "Hello World using jQuery Ajax";
Share with your friends!!