【问题标题】:calling wp_editor getting error getContent null调用 wp_editor 得到错误 getContent null
【发布时间】:2018-07-06 17:55:09
【问题描述】:

我从php 调用wordpresstinyMCE,并通过ajax 将其内容分配给表单数组键。
我不断收到错误:Cannot read property 'getContent' of null.
我读过 Wordpress wp_editor() not workingInclude TinyMCE plugins with Wordpress wp_editor? 等想法,但仍然无法将 tinyMCE 的内容放入 form array

JS:

var form            =   {
            action:             "submit_user_data",
            content:            tinymce.activeEditor.getContent(),
            title:              $("#inputTitle").val(),
            ingredients:        $("#inputIngredients").val(),
            time:               $("#inputTime").val(),
            utensils:           $("#inputUtensils").val(),
            level:              $("#inputLevel").val(),
            meal_type:          $("#inputMealType").val()
        };

PHP:

wp_editor( '', 'tinymcecontenteditor' );

问题源于tinymce.activeEditor.getContent() 电话。
有什么想法吗?
谢谢

【问题讨论】:

    标签: php jquery ajax wordpress tinymce


    【解决方案1】:

    在调用'tinymce 的方法和函数之后,我没有发现调用有任何问题。
    但不知何故(仍然无法弄清楚这个是留给公众的)我注意到如上所述从jquery 调用tinymce 并不能访问它的内容(显然......dah..)。 我发现我需要做的是,而不是调用getContent 函数,我必须触发triggerSave 函数并通过id 获取对象的val,所以:

    tinyMCE.triggerSave();
    var contents = $("#tinymcecontenteditor").val();
    

    在我将其内容分配给form array之前。

    表单数组更改为content: contents,

    shahnbaz's answer 为我指明了那个方向。

    【讨论】:

      【解决方案2】:

      听起来问题在于您的 WordPress 集成。只要 TinyMCE JS 在页面中,activeEditor 就应该始终返回编辑器实例。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-08
        • 2012-01-01
        • 2021-12-08
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        • 2019-12-31
        • 1970-01-01
        相关资源
        最近更新 更多