我遇到了一个问题,在后面的代码上触发了我的C#WebMethod并且收到了500个内部服务器错误。我不明白为什么它不会触及它,所以如果有人能告诉我什么是问题,那真是太好了。使用ajax调用WebMethod时出现500内部服务器错误
所以这是我的ajax调用,甚至与数据和数据类型没有被注释掉不起作用。
$('#chkBxAutoCost')
.click(function(e) {
$.ajax({
type: "POST",
url: "BatchReportCriteriaSelection.aspx/GetAutoJsonBatches",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: "{}",
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("Request: " +
XMLHttpRequest.toString() +
"\n\nStatus: " +
textStatus +
"\n\nError: " +
errorThrown);
},
success: function() { console.log("success") }
});
}
);
这是我背后的页面的方法代码:
[WebMethod]
public string GetAutoJsonBatches()
{
return autoJsonBatches;
}
所以我重视这个的WebMethod断点,它没有被击中。我很坚持,所以如果有人有任何洞察力,我将不胜感激。
的可能的复制[ASP.NET 500内部服务器错误,而从JavaScript调用的WebMethod](http://stackoverflow.com/questions/30011998/asp-net-500-internal -server-error-while-calling-webmethod-from-javascript) –
尝试使你的方法'静态':http://stackoverflow.com/questions/30011998/asp-net-500-internal-server-error-while-调用webmethod-from-javascript –
非常感谢。使它静态固定它。虽然我无法接受来自这里的答案!如果你在我的下面添加一个答案,我会接受它! :) – Seamy