保存数据到PHP / MySQL的在CKEditor的联编辑编辑、数据、MySQL、PHP

2023-09-10 13:19:41 作者:愈归

我想用新的CKEditor 4的内联编辑( HTTP ://docs.ckeditor.com/# /引导/ dev_inline节-2 ),但无法找到如何保存数据用PHP / MySQL的任何实际的例子! 你能帮助我吗?

I want to use "inline edit" of the new CKEditor 4 (http://docs.ckeditor.com/#!/guide/dev_inline-section-2), but can not find any example of how to save the data with PHP / MySQL. Can you help me?

推荐答案

这是我的样子已经在过去做到了:

This is the way I've done it in the past:

current_page_id 涉及到我们要更新的表行,否则我们也不会知道我们需要更新什么记录。

The current_page_id relates to the table row we wish to update, otherwise we wouldn't know what record we need to update.

<div id="editable">My body text</div>
<input type="hidden" name="page_id" id="current_page_id" value="10" />

<script type="text/javascript">

CKEDITOR.disableAutoInline = true;
CKEDITOR.inline('editable', {
    on: {
        blur: function( event ) {

            var params = {
                page_id: $("#current_page_id").val(),
                body_text: event.editor.getData()
            };

            $.ajax({
                url: 'php_file_to_post_to.php',
                global: false,
                type: "POST",
                dataType: "text json",
                data: params,
                success: function(result) {
                    console.log(result);
                }
            });

        }
    }
});

</script>

你的 php_file_to_post_to.php PHP文件的内部,你只是赶上了ajax post请求和更新基于关闭 PAGE_ID 变量,它也被张贴随着编辑的内容。

The inside of your php_file_to_post_to.php PHP file you simply catch the ajax post request and update the row based off of the page_id variable which has also been posted along with the edited content.