Just create a hidden input element in your form. (note the type)
<input type="hidden" name="myHiddenField">
Attach your data to the item value before submitting.
var imageData = canvas.toDataURL('image/png'); document.getElementsByName("myHiddenField")[0].setAttribute("value", imageData);
UPDATE
If your server requires a file name parameter in the data provided, include this line as the name of the input element.
<input type="hidden" name="filename"/>
This will trick the form into submitting your data with the "filename" parameter included.
If you want to use XMLHttpRequest for this, follow the example:
//Prepare data to be sent var imageData = canvas.toDataURL('image/png'); var params = "filename=" + imageData; //Initiate the request var httpRequest = new XMLHttpRequest(); httpRequest.open('POST', 'test.php', true); //Send proper headers httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); httpRequest.setRequestHeader("Content-length", params.length); httpRequest.setRequestHeader("Connection", "close"); //Send your data httpRequest.send(params);
Charlie h
source share