【发布时间】: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 应用程序提供服务...