I want to save a html canvas element as an image using php and jquery ajax. Here is my code for ajax.
var front_image=canvas.toDataURL("image/png"); //front image is a base_64 string $.ajax({ url:base_url+'tabs/profile/save_front_image', type:'POST', data:'front_image='+front_image, success:function(response){ } }); I m just doing echo in php echo $_POST['front_image'] so request and response are same.
When i use this code before ajax it loads image to new tab of browser
var w = window.open('about:blank', 'image from canvas'); w.document.write("<img src='" + frame_image + "' alt='from canvas'/>"); but when i put the same code on ajax response as bellow it doesn't work. Only a blank tab opens in browser. So i m not being able to save image as file.
var w = window.open('about:blank', 'image from canvas'); w.document.write("<img src='" + response + "' alt='from canvas'/>"); I compared string length of frame_image and response also. They are same. I m not sure why image is not loading in response. Please suggest me the answer thanks.