function captureAndUpload() {
var r = '';
html2canvas($("#PAINTING-DIAGRAMMA"), {
background:'#fff',
onrendered: function(canvas) {
var imgData = canvas.toDataURL('image/jpeg');
var url = 'loadImg.php';
$.ajax({
type: "POST",
url: url,
dataType: 'text',
data: {
screen : imgData
},
success: function(response){
response = "" + response
var ans = response.substr(12);
r = ans;
console.log( 'ans', ans )
},
error:function(xhr, ajaxOptions, thrownError){
console.log( xhr.responseText )
}
});
}
});
console.log( 'r', r )
}
function captureAndUpload(){
return new Promise((resolve,reject)=>{
html2canvas($("#PAINTING-DIAGRAMMA"), {
background:'#fff',
onrendered: function(canvas) {
var imgData = canvas.toDataURL('image/jpeg');
var url = 'loadImg.php';
$.ajax({
type: "POST",
url: url,
dataType: 'text',
data: {
screen : imgData
},
success: function(response){
response = "" + response
var ans = response.substr(12);
console.log( 'ans', ans );
resolve(ans);
},
error:function(xhr, ajaxOptions, thrownError){
console.log( xhr.responseText )
reject(xhr.responseText);
}
});
}
});
}
captureAndUpload().then(r=>{
console.log('r',r);
}).catch(error=>{
console.log(error);
});