1

I'm making an ajax call in the function as below

 function UploadPic() {
        debugger;
        // generate the image data
        var canvas = document.getElementById("canvas");
        var dataURL = canvas.toDataURL("image/png");


        // Sending the image data to Server
        $.ajax({
            type: 'POST',
            url: "baseimg.aspx",
            data: { imgBase64: dataURL },
            success: function () {
                alert("Done, Picture Uploaded.");
                window.opener.location.reload(true); // reloading Parent page

                window.close();
                window.opener.setVal(1);

                return false;
            }
        });
    }

And in the page load I'm trying to get the value as

protected void Page_Load(object sender, EventArgs e)
{
    StreamReader reader = new StreamReader(Request.InputStream); 
    string Data = Server.UrlDecode(reader.ReadToEnd());
    reader.Close();
}

In the dataURL I'm getting the value but in the page load 'string Data' is coming as empty.

I have referred to Capturing Image From Web Cam in ASP.Net to make this functionality.

The ajax is hitting successfully to the code then coming back and executing the success portion in the ajax call.

I'm finding no way out of it.

Sribin
  • 307
  • 4
  • 16

1 Answers1

0

Since it is a POST operation, try checking the form variable like the following for the data string:

Request.Form["imgBase64"]
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • Thank you so much but this is not working.There is no
    tag in the page where I'm calling Ajax.The debugging just exits on this line no exception,no stopping of debugging .it is like a silent get out from debugging.
    – Sribin Mar 15 '18 at 11:14
  • A form tag would not be necessary since you are invoking the post operation in AJAX... Throw a breakpoint in the code-behind and watch the execution path it is following. Check to see if anything is posting back... – Brian Mains Mar 15 '18 at 11:31
  • It is not returning anything back.I tried with the form tag but my Image capturing functionality is not working at all which is all written in Js. – Sribin Mar 15 '18 at 11:35
  • Maybe this approach will work: https://stackoverflow.com/questions/34779799/upload-base64-image-with-ajax – Brian Mains Mar 15 '18 at 11:47
  • What will be the best way to get the value in code behind if the ajax is looks likes this
        var formData = new FormData();
                formData.append('picture', blob);
                $.ajax({
                    url: "baseimg.aspx",
                    type: "POST",
                    cache: false,
                    contentType: false,
                    processData: false,
                    data: formData
                })
            .done(function (e) {
                alert('done!');
            });
    – Sribin Mar 15 '18 at 12:21
  • Tried converting and sending as blob. Still no go. – Sribin Mar 15 '18 at 13:03