如何保存行内编辑器的内容在服务器上? [英] How do I save inline editor contents on the server?
问题描述
我用CKEDITOR,允许用户联编辑登录后页面上的内容。
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();
但我不知道如何将数据发送到一个脚本,这样我就可以更新数据库。这将是冷静,如果脚本运行每当有人取消选中 CONTENTEDITABLE
元素......但是我不知道,如果多数民众赞成甚至有可能。
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! :)
我的网站使用PHP / MySQL的建立。
My site is built using php/mysql.
推荐答案
事情是这样的:
CKEDITOR.disableAutoInline = true;
CKEDITOR.inline( 'editable', {
on: {
blur: function( event ) {
var data = event.editor.getData();
// Do sth with your data...
}
}
} );
请注意,这不会与其他类似的交互工作:用户名为 editor.setData()
或用户关闭了网页,一边编辑。内容将在这样的情况下会丢失。如果我是你,我宁愿定期检查新数据:
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 );
};
})();
这篇关于如何保存行内编辑器的内容在服务器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!