[Solved] WebMethod not calling using jQuery AJAX in ASP.Net

Last Reply 3 months ago By AbdulHaque

Posted 4 months ago

Hello everyone,

I am using jQuery Ajax post value from client side but its not working.

I am unable to figure kindly please help me.

Any suggestions will be appretiated.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="AJAX.Test" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-3.4.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btn').click(function () {            
            var no = 123;
            $.ajax({
                url: 'Test.aspx/show',              
                method: 'post',
                contentType: 'ápplication/json',
                data: '{Id:' + no + '}',
                dataType: 'json',
                success: function (data) {
                    alert(data.d.id);
                },
                failure: function (data) {
                    alert(data.d);
                }
            });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input type="button" id="btn" value="Submit" />
    </form>
</body>
</html>

 

namespace AJAX
{
    public partial class Test : System.Web.UI.Page
    {       
        [WebMethod]
        public static string show(string id)
        {
            return id;
        }
    }
}

 

Posted 3 months ago

Thank you all for your valuable reply.

Actually the problem is with Route.Config.cs file under this I have changed RedirectMode.Permanent to RedirectMode.off and it works for me.

Thanks once again regards

Changed RedirectMode.Permanent to RedirectMode.off;