I want to save and retrieve HTML 5 canvas that I have drawn using Fabric.js, a JavaScript library, into MySQL table using PHP that has a field namely cnvs_obj
of BLOB
type. I have seen a lot of tuts and Q/A sessions but none has step by step way of teaching. How can I do this, would be very much thankful to you. Here is my canvas example.
EDIT:
Here is my complete code:
<canvas id="c" style="border:1px solid black;" width="500px" height="300px" ></canvas>
<button onclick="myFunction()" id="btn2">Click me</button>
<script type="text/javascript" src="fabric.min.js"></script>
<script type="text/javascript">
var canvas = new fabric.Canvas('c');
$(function () {
//canvas.stateful = true;
var wel = new fabric.Text('Welcome to FabricJs', {
fontFamily: 'Delicious_500',
backgroundColor: 'red',
left: 80,
top: 100
});
canvas.add(wel);
});
canvas.renderAll();
function myFunction() {
console.log(JSON.stringify(canvas));
var str_json = JSON.stringify(canvas);
// send JSON to PHP
$.ajax({
type: 'POST',
url: 'hallo_json.php',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: { hallo_str: JSON.stringify(str_json) },
});
alert(str_json);
}
</script>
Here is PHP code:
<?php
header('Content-type: text/html');
print_r(json_decode($_POST['str_json']));
Now I can generate JSON, but error 200 arises. I don't where is the error.