How do I save inline editor contents on the server? [duplicate]

十年热恋 提交于 2019-11-27 05:38:20

问题


This question already has an answer here:

  • ckeditor inline save/submit 3 answers

I'm using CKeditor to allow users to inline edit the content on a page once logged in.

I know I can access the data using:

var data = CKEDITOR.instances.editable.getData();

but I don't know how to send the data to a script so I can update the database. It would be cool if the script ran each time someone deselected a contenteditable element... but I don't know if thats even possible.

Any tips would be great! :)

My site is built using php/mysql.


回答1:


Something like this:

CKEDITOR.disableAutoInline = true;

CKEDITOR.inline( 'editable', {
    on: {
        blur: function( event ) {
            var data = event.editor.getData();
            // Do sth with your data...
        }
    }
} );

Note that this won't work with other interactions like: user called editor.setData() or user closed the web page while editing. Contents will be lost in such cases. If I were you, I'd rather periodically check for new data:

CKEDITOR.disableAutoInline = true;

var editor = CKEDITOR.inline( 'editable', {
    on: {
        instanceReady: function() {
            periodicData();
        }
    }
} );

var periodicData = ( function(){
    var data, oldData;

    return function() {
        if ( ( data = editor.getData() ) !== oldData ) {
            oldData = data;
            console.log( data );
            // Do sth with your data...
        }

        setTimeout( periodicData, 1000 );
    };
})();



回答2:


CKEDITOR.inline('editable'  ,{
        on:{
            blur: function(event){
                if (event.editor.checkDirty())
                    console.log(event.editor.getData());
            }
        }
    });

Try this.




回答3:


It looks like "blur" event might help you: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#event:blur



来源:https://stackoverflow.com/questions/13922002/how-do-i-save-inline-editor-contents-on-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!