具有如下功能:
function uploadPic() {
var imgData = document.getElementById("myCanvas").toDataURL();
window.location = "myPHPfile.php?imageData=" + imgData;
}
由于其大尺寸,将 imgData 变量传递到php页面的最佳方法是什么? 提前谢谢!
答案 0 :(得分:1)
用户发布传递大数据的请求。你可以使用jQuery post方法
$.post('myPHPfile.php', { imageData: imgData }, function(data) {
// completed
});
或创建并发布表单:
function uploadPic() {
var imgData = document.getElementById("myCanvas").toDataURL();
var form = document.createElement('form');
form.method = "POST";
form.action = "myPHPfile.php";
var hidden = document.createElement('input');
hidden.type = 'hidden';
hidden.name = 'imageData';
hidden.value = imgData;
form.appendChild(hidden);
document.body.appendChild(form);
form.submit();
}