$5 correct answer - fabric.js with json export/import
hello i am using the fabric.js framework with html5 canvas. i'm hoping someone can help me in here that has used this... this basically is an interactive canvas where you can add text, svgs - scale/resize/skew. what i'm doing is exporting the whole canvas into JSON and saving it in my DB. then i call the json back through a function. but it's not working right... the JSON holds the info on how to build the objects, boxes, rectangles, triangles, text... if i just have those objects then it builds it just fine... however when i export an SVG and try to call it (with or without other objects) it fails... the data is too long to be stored in json so fabric has you set a url to the saved svg on the server and just a "url" parameter. this is only for SVG (images) not for the other objects. so if i just have those..they work fine...but when i start using SVGs, it fails to import them back
if you look in the json var you see the object that would be coming from the database. if you take out the svg data and just leave the text data you would see that it builds it just fine. $5 to first correct answer via paypal
errors solved: before I used canvas.loadFromJSON. because I used canvas.toDatalessJSON() to save it, i have to use loadFromDatalessJSON to retrieve it. if you weren't importing an svg through a URL then you could use toJSON() and loadFromJSON. i hope this helps someone with this same problem
Code:
canvas.loadFromDatalessJSON(json, function() {
alert(' this is a callback. invoked when canvas is loaded! ');
});