StorageManager: Loading from remote storage
So when I set: contentTypeJson: true, resulting in: I can now load from the database. But, now it will not save, because it is sending the data as JSON. How can I send the data as POST variables, but receive it as JSON?
Read full answer below ↓Question
Hi,
I'm trying to read the HTML and CSS from my database. When I try to load it into the editor, nothing displays. I can store the data just, just cannot load it.
Is this the correct format for the data when you are loading it?
Content-type
application/json
Preview
{gjs-assets: "", gjs-components: "",…}
gjs-assets : ""
gjs-components : ""
gjs-css : "*{box-sizing: border-box;}body{margin:0;}.c1077{padding:10px;}"
gjs-html : "<div class="c1077">Insert your text here</div>"
gjs-styles : ""
Response
{"gjs-assets":"","gjs-components":"","gjs-css":"*{box-sizing: border-box;}body{margin:0;}.c1077{padding:10px;}","gjs-html":"<div class=\"c1077\">Insert your text here<\/div>","gjs-styles":""}
Answers (3)
So when I set:
contentTypeJson: true,
resulting in:
storageManager: {
type: 'remote',
autoload: true,
stepsBeforeSave: 1,
contentTypeJson: true,
urlStore: "/save-template/2",
urlLoad: "/load-template/2",
params: {}, // For custom values on requests
},
I can now load from the database. But, now it will not save, because it is sending the data as JSON. How can I send the data as POST variables, but receive it as JSON?
@shareefhiasat I explain here how to use them https://github.com/artf/grapesjs/wiki/Storage#store-and-load-templates
@DeathStapler This is what mine looks like:
{
"gjs-css":"*{box-sizing: border-box;}body{margin:0;}.c1050{padding:10px;}",
"gjs-html":"<div class="c1050">Hi</div>",
"gjs-assets":"[]",
"gjs-styles":"[]",
"gjs-components":"[]"
}
The thing that jumps out at me at first is that assets, components and styles should be arrays, you have empty strings.
The Content-Type is correct.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1429
Empty content when load from remote storage if components array is not empty
I have problem loading stored remote content into the editor when the JSON contains non empty gjs-components My JSON data looks like this w...
Issue #1985
[BUG] Autosave with remote storage doesn't send network requests
OS: Windows 10 Browser: Chrome 73 GrapesJS version: 0.14.57 I have remote storage configured using this call to grapesjs.init(): While I se...
Issue #1778
Unable to load from remote
I'm trying to load from a remote URL, and nothing ever loads. This is the response I get back from the load function: Loaded {0: "↵", 1: "{...
Issue #1302
Invalid JSON String - Load Data
I had some problems loading templates. It did not work both the storage in a .json file and the processing in a mysql database. my loading....
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.