0

我正在练习 jquery ajax 调用。当我运行我的项目时会发生什么情况,它给出了 INTERNAL SERVER ERROR 500。这个错误是什么意思,我如何遇到这个错误?

我创建了一个示例项目,在其中添加了以下代码:

   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();
        }
    }
}

我的 aspx 代码文件:

    <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>
4

1 回答 1

1

定义你的函数公共...像这样从 Jquery 访问

 [WebMethod]
//define function as public....
        public static string GetDateTime()
        {
            return DateTime.Now.ToString();
        }
于 2013-05-18T16:52:09.613 回答