C# 在ASP.NET Webforms中使用Ajax调用时出现错误500
我试图在html页面中调用一个简单的void,但它显示错误500。 谁能帮帮我我快疯了! 在控制台日志中显示此错误:C# 在ASP.NET Webforms中使用Ajax调用时出现错误500,c#,asp.net,ajax,C#,Asp.net,Ajax,我试图在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/
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>
正如@Zaki所评论的,这是我的错误,我应该将ajax的数据部分更改为:
数据:“{param:'1'}”将数据更改为:数据:“{param:'1'}”,非常感谢我忘记更改param,另一个问题:我读到microsoft不再支持WebMethods,是真的吗?我该怎么办?你在哪里读到的?我确信这不是真的,如果是的话,你可以随时创建web api或wcf服务并为你的web应用程序服务。。。
[WebMethod]
[ScriptMethod]
public static int SaveUser(int param)
{
return 10;
}