GrapesJS - Storing HTML on server side

Author - Webner
20.04.2018
|
0 Comments
|

In GrapeJS to save html code of document in database use your own save function (like saveContent() in this example) inside editor’s ‘storage:store’ event method.

Example:

editor.on('storage:store', function(e) {
saveContent(); //your method where you store html content of document in DB using ajax
})

Here is the saveContent() method – (getting html and css content from GrapesJS and sending it to php file to save through ajax)

function saveContent()
{
var iframe = document.getElementsByTagName('iframe')[0];
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var frameBody = innerDoc.querySelector('body');
var style = frameBody.querySelector('style');
var htmlContent = frameBody.querySelector("#wrapper");
var html=htmlContent.innerHTML; //get html content of document
var css=editor.getCss(); //get css content of document
$.ajax({
url: "/proposals/ajax/ajax.php",
data :{'html':html,'css':css},
dataType: 'json',
async:true,
type:'POST',
beforeSend: function () {
},
complete: function (data) {
},
success: function(result) {
},
error:function(data) {
}
});
}
Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

Send your message