I am trying to load a Base64 string from my database into a canvas.
I got this line from the reverse method: I saved it in my database after drawing on canvas. So now I want to upload it back to another canvas. I tried this code, which I found on the Internet and somewhere else here in StackOverflow, but it does not work.
<script type="text/javascript"> $(document).ready(function(){ var canvas = document.getElementById("loading_canvas"); var ctx = canvas.getContext("2d"); var image = new Image(); $.post('doodles/load', function(data) { image.src = data; }); ctx.drawImage(image, 0, 0); }); </script>
I am loading data from my database using ajax call.
If I alert() data var, it displays an encoded Base64 string. So this is actually not the case. I just end up with a blank canvas all the time.
Does anyone know what I'm doing wrong here? Many thanks!
source share