一般在后台获取ckeditor的内容只需要前台提交表单到后台,使用request["ck_name"]就能获取到,ck_name为ckeditor的name属性值;但是在Jquery中使用ajax的serialize()方法提交表单到一般处理页面,ckeditor作为表单内容一块提交;但是在后台获取不到ckeditor的内容;经查资料需要在psot提交前需要做以下操作:
<script type="text/javascript">
$(function () {
var editor = CKEDITOR.replace("editor1", { "toolbar": "Basic" }); //显示编辑器
CKFinder.setupCKEditor(editor, "ckfinder/"); //设置图片管理组件
//处理CKEDITOR的值
function CKupdate() {
for (instance in CKEDITOR.instances)
CKEDITOR.instances[instance].updateElement();
}
$("#subAjax").click(function () {
CKupdate(); //在提交表单前需要做以上处理
$.post("handler/Handler1.ashx", $("#form1").serialize(), function (data) {
if (data == "sucess") { alert("成功"); } else { alert("失败"); }
});
});
})
</script>
这样,在jquery form提交表单之前,使CKEditor更新相关的字段属性,提交时就不会丢失数据。