0

I have a web application C#/HTML and I must pass an image from js --> C#. The command I use is canvas.toDataURL('image/png') but the system got in crash. I use IE10.

Is there any suggest?? Thanks...

[UPDATE] Scuse me..I have a setTimeout to delay the call.When timer elapsed, the error is

Uncaught TypeError: undefined is not a function

It seams like a variable visibility. Is it possible?

5
  • Pass an image from file or from canvas? Because the code you posted just works in IE/Chrome/FF. Commented Mar 2, 2015 at 15:51
  • I have a canvas and send the content of the canvas --> C#. I have a webBrowser in C# but the call, crash. Commented Mar 2, 2015 at 15:53
  • You give us very little information to work with.. Where did it crash? In the browser? In the back-end? Did it work on other browsers? Commented Mar 2, 2015 at 15:57
  • I have updated the description. Have any ideas? Commented Mar 2, 2015 at 16:17
  • It is a little more clear.. Thanks. It look like your canvas variable is not defined properly. Commented Mar 2, 2015 at 16:19

1 Answer 1

1

First you need add an input file:

<form id="submitfile" action="youraction" method="post" enctype="multipart/form-data">
  <input type="file" id="filetoup" name="file" accept="image/*" >

then you should use ajax:

$('#submitfile').ajaxForm({
complete: function(xhr) {
    alert("Upload complete");   
} 
}); 

Also you can use the way you are using

var canvasData = canvas.toDataURL("image/png");
var ajax = new XMLHttpRequest();
ajax.open("POST",'controller/action',false);
ajax.setRequestHeader('Content-Type', 'application/upload');
ajax.send(canvasData);
Sign up to request clarification or add additional context in comments.

2 Comments

Scuseme I quite confuse... I have a webcam and take a screen: then I would pass the image to C#. Can you explain how?
Well, take a look this stackoverflow.com/questions/4912092/… let me know if you cant get it.

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.