我尝试将画布数据作为图像发送,但是当图像很大时,它不会发送数据,所以我尝试作为表单数据发送,但我被困在接收代码中。代码隐藏作为 htmlinputelementobject 接收。我怎样才能收到它?有人可以帮忙吗。
html:
var data = canvas.toDataURL("image/png");
data = data.substr(data.indexOf(',') + 1).toString();
var dataInput = document.createElement("input");
dataInput.setAttribute("name", "imgdata");
dataInput.setAttribute("value", data);
dataInput.setAttribute("type", "hidden");
var myForm = document.createElement("form");
myForm.appendChild(dataInput);
阿贾克斯:
$.ajax({
url: "HTML5Camera.aspx/Upload",
type: "POST",
// data : $('form').serialize(),
data: "{ 'image': '" + data1 + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, status) {
alert('success')
}
});
代码隐藏:
[WebMethod(EnableSession = true)]
public static string Upload(string image)
{
}