【问题标题】:Getting error 500 while using Ajax call in ASP.NET Webforms在 ASP.NET Webforms 中使用 Ajax 调用时出现错误 500
【发布时间】:2016-02-23 16:50:19
【问题描述】:

我试图在 html 页面中调用一个简单的 void,但它显示错误 500。 谁能帮帮我,我快疯了! 在控制台日志中显示此错误:

POST http://localhost:15041/Default.aspx/SaveUser 500 (Internal Server Error)

我的html代码:

<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">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True"></asp:ScriptManager>


    </form>
    <script>
        $.ajax({
            type: "POST",
            url: "/Default.aspx/SaveUser",
            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>

这是我的 C# 代码:

[WebMethod]
        [ScriptMethod]
        public static int SaveUser(int param)
        {
            return 10;
        }

【问题讨论】:

  • 将您的数据更改为:data: "{param:'1'}",
  • 非常感谢我忘了更改参数,另一个问题:我读到微软不再支持 WebMethods,是真的吗?我该怎么办?
  • 你在哪里读到的?确定这不是真的,如果是这样,您始终可以创建 Web api 或 wcf 服务并为您的 Web 应用程序提供服务...

标签: c# asp.net ajax


【解决方案1】:

正如@Zaki 评论的那样,这是我的错误,我应该将 ajax 的数据部分更改为: 数据:“{param:'1'}”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 2016-03-25
    • 2020-02-06
    相关资源
    最近更新 更多