1
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. 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. But still nothing.

[WebMethod]
    public static bool testingPOST(string value)
    {
        
        return true;
    }
7
  • To start, you need to configure your server app to report the full details of the error so you have a better idea of what's wrong. Commented Nov 30, 2021 at 0:23
  • try to change data: '{ "imageData" : "' + image + '" }' to data: { value : image }, Commented Nov 30, 2021 at 0:29
  • 1
    The 500 error details are hidden by default for security reasons. It should be disabled for production servers. The details on how to do this varies depending on the app technology -- so you really need to search for a specific setup (and sometimes version). Commented Nov 30, 2021 at 0:34
  • I have changed the suggestion by Cura but still no fix. Commented Nov 30, 2021 at 10:00
  • I am currently using in the webconfig <httpErrors errorMode="Detailed" /> <asp scriptErrorSentToBrowser="true"/> but only getting 500 error in the details in the browser Commented Nov 30, 2021 at 10:00

2 Answers 2

1

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.

I edited the webconfig with the following and it now works!

<system.web.extensions> 
<scripting> 
<webServices> 
<jsonSerialization maxJsonLength="500000000"/>
 </webServices> 
</scripting> 
</system.web.extensions>
Sign up to request clarification or add additional context in comments.

Comments

0

WebMethod tells the applicaiton it is accessed through and XML WebService request. if you want to access it through POST you will need the ScriptMethod attribute:

[ScriptMethod]
public static bool testingPOST(string value)
{
    return true;
}

See this answer for more info:

what is web method attribute in web service?

2 Comments

Still getting the 500 error using this change.
[Webmethod] was required, when I changed it to [Scriptmethod] I would get an error that there was a missing web method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.