[英]Getting error 500 while using Ajax call in ASP.NET Webforms
我試圖在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;
}
正如@Zaki所說,這是我的錯誤,我應該將ajax的data部分更改為:data:“ {param:'1'}”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.