![](/img/trans.png)
[英]Getting 500 Internal Server Error when calling a WebMethod using ajax
[英]Getting Error: 500 Internal server error when using AJAX POST to C# Webmethod
var image = document.getElementById("capture").toDataURL("image/png");
image = image.replace('data:image/png;base64,', '');
alert(image);
$.ajax({
type: 'POST',
url: 'Info.aspx/testingPOST',
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(response, textStatus, jqXHR) {
alert("File Saved");
},
error: function (jqXHR, exception) {
var msg = 'error';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert("error:" + msg);
}
})
}
使用上述方法将我的 canvas 图像发布到 Web 方法,然后在下面的 c# 中进行简单检查。 我收到错误 500。我查看了各种帖子,但似乎找不到任何可以使其正常工作的调整,我已经关闭了 app_start 中的自动重定向和其他各种建议。 但还是一无所获。
[WebMethod]
public static bool testingPOST(string value)
{
return true;
}
WebMethod
告诉应用程序通过它访问它和 XML WebService 请求。 如果你想通过POST
访问它,你需要ScriptMethod
属性:
[ScriptMethod]
public static bool testingPOST(string value)
{
return true;
}
有关更多信息,请参阅此答案:
我在谷歌浏览器中使用了开发者工具,点击了错误,然后在预览中..它告诉我 json 字符串长度太长。
我用以下内容编辑了 webconfig,它现在可以工作了!
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="500000000"/>
</webServices>
</scripting>
</system.web.extensions>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.