I am trying to call a simple void in html page but it shows error 500. Can anyone help me i'm getting crazy! In console log shows this error :
POST http://localhost:15041/Default.aspx/SaveUser 500 (Internal Server Error)
my html code :
<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>
and here is my C# code :
[WebMethod]
[ScriptMethod]
public static int SaveUser(int param)
{
return 10;
}
正如@Zaki所说,这是我的错误,我应该将ajax的data部分更改为:data:“ {param:'1'}”
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.