ckeditor 插入或更新在第一次尝试时不起作用

ckeditor insert or update doesnt work in first try

我在使用 CKEditor 并将其信息发送到数据库时遇到了一些问题。 它工作得很好,我拥有所有功能,但是当我通过 ajax 请求将它发送到 PHP 时,它不会假设文本第一次进入 CKEditor。它仅在我第二次发出 ajax 请求后才有效。好像CKEditor不是实时的,只有在X次后才保存我输入的信息,但我找不到任何相关的东西。

我的初始化:

        if (jQuery('#js-ckeditor:not(.js-ckeditor-enabled)').length) {
        CKEDITOR.replace('js-ckeditor');

        // Add .js-ckeditor-enabled class to tag it as activated
        jQuery('#js-ckeditor').addClass('js-ckeditor-enabled');
    }

我提出请求的函数:

        $.ajax({ url: '../inc/call.php',
        enctype: 'multipart/form-data',
        processData: false,
        contentType: false,
        cache: false,
        data: formData,
        type: 'POST',
        beforeSend: function(){
            $("#article_btn").html('<i class="fa fa-cog fa-spin"></i>');
            $("#article_btn").attr("disabled", true);
        },
        success: function(output) {...}});

还有一个问题,将这些信息保存到数据库的最佳方式是什么? 目前我正在使用 htmlspecialchars 和 htmlspecialchars_decode,但是当使用某些功能(表格、颜色)时,它确实不能很好地工作并且没有以正确的方式将所有内容保存在数据库中。

我会回答你的第一个问题:

如果您正在使用 AJAX,请在通过调用 https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#method-updateElement. This topic is actually known. Please see e.g. https://dev.ckeditor.com/ticket/9913#comment:2.

将数据发送到服务器之前手动更新 textarea