weixin_33682790 2017-05-10 17:14 采纳率: 0%
浏览 57

使用jQuery Ajax保存Tinymce

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
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分