javascript - $.post inside html2canvas? -
i have 2 functions:
number one
html2canvas($("#screenshot"), { onrendered: function(canvas) { $('.ha').append(canvas); } });
number two
$.post("save.php",{ xcv : canvas }, function(data){ if (data == 1) { $('.cropped').empty(); $('.cropped').append('<img src="' + data + '">'); $('.cropped').append('<h2>is okay?</h2>'); } else { alert(thecanvas); } });
function number 1 takes screenshot of div-container "screenshot" , shows in div-class "ha". function number 2 should give canvas php file transform canvas pyhsical file. if successful php-file return "1" , post picture on page because "data" keeps filename. tried this:
html2canvas($("#screenshot"), { onrendered: function(canvas) { $('.ha').append(canvas); $.post("save.php",{ xcv : canvas }, function(data) { if (data == 1) { $('.cropped').empty(); $('.cropped').append('<img src="' + data + '">'); $('.cropped').append('<h2>is okay?</h2>'); } else { alert(thecanvas); } }); } });
but not working. thing if use both functions seperatly working fine.
the whole thing looks this:
$('#btncrop').on('click', function(){ html2canvas($("#screenshot"), { onrendered: function(canvas) { $.post("save.php",{ xcv : canvas }, function(data) { if (data != '') { $('.cropped').empty(); $('.cropped').append('<img src="' + data + '">'); $('.cropped').append('<h2>is okay?</h2>'); } else { alert("error!"); } }); } }); })
and here screenshot after pushed button
wolff, thank question! made me figure out solution, under impression base64 string "canvas" didnt. needed add a
var x = canvas.todataurl();
and work "x" , not "canvas", no working fine. whole thing looks this:
$('#btncrop').on('click', function(){ html2canvas($("#screenshot"), { onrendered: function(canvas) { var x = canvas.todataurl(); $.post("save.php",{ xcv : x }, function(data) { if (data != '') { $('.cropped').empty(); $('.cropped').append('<img src="' + data + '">'); $('.cropped').append('<h2>is okay?</h2>'); } else { alert(thecanvas); } }); } }); })
thank again!
Comments
Post a Comment