AJax 内部服务器错误 500

AJax Internal Server Error 500

本文关键字:错误 服务器 内部 AJax      更新时间:2023-09-26

我有一个页面方法问题,我在 ASP.net 网络表单上有这个页面方法

   [WebMethod(true)]
    public static int GetInt(int id){
          return 10;
   }

我像这样从 JQuery 调用它

   $.ajax({
            type: "POST",
            url: "webforms.aspx/GetInt",
            data: "{id:'1'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
            },
            error: function (err) {
            }
        });

这一切都很好用,当我在服务器端放置一个断点时,它会命中,但是由于某种奇怪的原因,我在 PageMethod 返回后,我收到 ajax 调用的错误回调永远不会成功!任何想法。

我不能在这个上使用脚本管理器!我打开任何跨浏览器解决方案!

我使用了您的代码,没有任何问题。这是我的确切代码:

网络表单1.aspx

<head runat="server">
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
<script>
    $.ajax({
        type: "POST",
        url: "/WebForm1.aspx/GetInt",
        data: "{id:'1'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert("SUCCESS: " + msg.d);
        },
        error: function (err) {
            alert("FAILURE");
        }
    });
</script>
</body>
</html>

网络表单1.aspx.cs

using System.Web.Services;

namespace WebApplication3
{
public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    [WebMethod(true)]
    public static int GetInt(int id)
    {
        return 10;
    }
}
}