I am using Tinymce as an editor in my application. I need the user to be able to save the content from the Tinymce into a MySQL database. I know the backend works fine as I can save content from regular input to the database, but Tinymce is not working properly. The content is being posted to my web application as:
[object Object]
Tinymce init
<script>
tinymce.init({
selector: "input.form-control",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste", "save"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | save",
save_enablewhendirty : false,
save_onsavecallback: function () {var todo = tinyMCE.get('content'); createTodo(todo); countTodos(); console.log(todo)}
});
</script>
This is my function to create the object that Tinymce content is saved to.
function createTodo(text) {
$.post("/stuffs/" + text)
.done(function (result) {
var markup = '<li class="ui-state-default"><div class="checkbox"><label><input type="checkbox" value="" /><p>' + text + '</p></label></div></li>';
$('#sortable').append(markup);
$('.add-todo').val('');
})
.fail(function (jqXHR, textStatus, errorThrown) {
alert('Documents cannot be added!');
})
}
From my console.log, in case it is helpful:
Object { documentBaseUrl: "http://localhost:8080/", settings: Object, id: "content", isNotDirty: true, plugins: Object, documentBaseURI: Object, baseURI: Object, contentCSS: Array[1], contentStyles: Array[4], _eventDispatcher: Object, 54 more… }
And this is present in console.log too
XML Parsing Error: no root element found
Location: http://localhost:8080/stuffs/[object%20Object]
Line Number 1, Column 1:
P.S. my application is in Spring Boot.
UPDATE: I am able to pass HTML content in an alert box using the code below in my save_onsavecallback.
var mce = tinyMCE.get('content'); var todo = mce.getContent(); alert(todo);
However, I get a 405 "Method Not Allowed"
Spring Tool Suite says in the console:
o.s.web.servlet.PageNotFound Request method 'POST' not supported