【发布时间】:2018-09-06 07:36:55
【问题描述】:
我正在尝试执行 ajax POST,但总是返回 500 服务器错误。
为了进行测试,我简化了请求。
Javascript 代码:
$(document).ready(function() {
// Add the page method call as an onclick handler for the div.
$("#prova").click(function() {
$.ajax({
type: "POST",
url: "Solicitud.aspx/GetDate",
data: {someParameter: "some value"},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
console.log("Resposta"+ msg.d);
}
});
});
});
类代码
namespace picovirgiliop
{
public partial class Solicitud : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string GetDate(string someParameter)
{
return DateTime.Now.ToString();
}
...
编辑
POST http://localhost:63010/Solicitud.aspx/GetDate 500(内部服务器错误)
- 发送@jquery-3.3.1.js:9600
- ajax@jquery-3.3.1.js:9206
- (匿名)@ Solicitud:300
- 调度@jquery-3.3.1.js:5183
- elemData.handle @ jquery-3.3.1.js:4991
【问题讨论】:
-
响应正文是否为您提供了有关错误的线索?
-
您能否发布响应正文的屏幕截图
-
如果我转到 localhost/Solicitud.aspx/GetDate 页面,它打开了 solicitud 页面并返回 200。不要返回 500 错误的更多信息,我在编辑部分复制消息。
-
删除
contentType: "application/json; charset=utf-8",选项(您没有对数据进行字符串化) -
如果我删除 contenttype,不会返回 500 错误,但也不会返回成功控制台日志