[英]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);
}
})
}
Using the above to post my canvas image to the Webmethod and then just a simple check in c# below.使用上述方法将我的 canvas 图像发布到 Web 方法,然后在下面的 c# 中进行简单检查。 I am getting error 500. I have looked on various posts and can't seem to find any tweak that gets this working, I have turned off the auto-redirect in app_start and various other suggestions.
我收到错误 500。我查看了各种帖子,但似乎找不到任何可以使其正常工作的调整,我已经关闭了 app_start 中的自动重定向和其他各种建议。 But still nothing.
但还是一无所获。
[WebMethod]
public static bool testingPOST(string value)
{
return true;
}
WebMethod
tells the applicaiton it is accessed through and XML WebService request. WebMethod
告诉应用程序通过它访问它和 XML WebService 请求。 if you want to access it through POST
you will need the ScriptMethod
attribute:如果你想通过
POST
访问它,你需要ScriptMethod
属性:
[ScriptMethod]
public static bool testingPOST(string value)
{
return true;
}
See this answer for more info:有关更多信息,请参阅此答案:
what is web method attribute in web service? web 服务中的 web 方法属性是什么?
I used the developer tools in Google Chrome, and clicked on the error, then on preview.. it showed me that the json string length was too long.我在谷歌浏览器中使用了开发者工具,点击了错误,然后在预览中..它告诉我 json 字符串长度太长。
I edited the webconfig with the following and it now works!我用以下内容编辑了 webconfig,它现在可以工作了!
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="500000000"/>
</webServices>
</scripting>
</system.web.extensions>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.