首页 > 解决方案 > 使用 AJAX 发送更多数据

问题描述

我有一个小程序,可以将 div 转换为画布,然后像照片一样保存在服务器中。问题如下:我正在使用 ajax 发送图像的 php 数据,但我需要发送必要的 id,这是代码:

function(){
html2canvas(document.getElementById("contenedor-pizarra-postural")).then(function (canvas) {
//Here is the ID thats i need to send
let idConsulta = document.getElementById("idConsulta").value;
var ajax = new XMLHttpRequest();
ajax.open("POST", "php/cargarPlanillas.php", true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//This is working only for the image data but i need to send the idConsulta variable :(
ajax.send("imagePostural=" + canvas.toDataURL("image/jpeg", 0.9))
})
ajax.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
});
}

标签: javascriptphpajax

解决方案


推荐阅读