0

I am practicing jquery ajax call. What happens is when i run my project it gives INTERNAL SERVER ERROR 500. What does this error means and how do I encounter this error?

I created a sample project in which i added this code:

   namespace sample
{
    public partial class jqAjaxcall : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                GetDateTime();
        }
        [WebMethod]
        private static string GetDateTime()
        {
            return DateTime.Now.ToString();
        }
    }
}

My aspx code file:

    <script type="text/javascript" src="Library/js/jquery-1.9.1-min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            // Add the page method call as an onclick handler for the div.
            $("#Result").click(function () {
                $.ajax({
                    type: "POST",
                    url: "jqAjaxcall.aspx/GetDateTime",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        // Replace the div's content with the page method's return.
                        $("#Result").text(msg.d);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="Result">
        Click here for the time.</div>
    </form>
</body>
</html>

1 Answer 1

1

Define Your Function Public...to Access from Jquery like this

 [WebMethod]
//define function as public....
        public static string GetDateTime()
        {
            return DateTime.Now.ToString();
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.