Monday, September 17, 2018

jQuery Ajax GET with params using WebMethod in c#

jQuery Ajax GET with params using WebMethod in c#

Code Snippet:
UI:
            <asp:Button ID="Button1" runat="server" Text="Call Ajax Get" OnClientClick="AjaxCall2();" />


jQuery:

        function AjaxCall2() {
            debugger;
            $.ajax({
                type: "GET",
                url: "AjaxTest.aspx/TestAjaxCallGET?name='Radha'",
                contentType: "application/json; charset=utf-8",
                dataType: "text",
                async: true,
                success: function (response) {
                    alert("Success");
                },
                failure: function (response) {
                    alert("failure");

                }
            });
        }


WebMethod C#

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
        public static string TestAjaxCallGET(string name)
        {
            return name;
        }

No comments:

Post a Comment