Ajax提交表单时获取不到 KindEditor 内容

1、问题:当用Ajax提交表单时,KindEditor的内容获取不到,HTML数据获取不了。

2、原因:jax提交时,KindEdito的HTML数据还没有同步到表单中来。

3、解决:使用http://kindeditor.net/doc3.php?cmd=config的afterBlur属性。

<  type=\"text/ \">
	KindEditor.ready(function (K) {
		window.editor = K.create(\'#AContent\', {
			//关键所在,当失去焦点时执行this.sync(),同步输入的值到textarea中;
			afterBlur: function () { this.sync(); } 
		});
	});
</ >

4、部分代码:

<form id=\"add_form\" enctype=\"multipart/form-data\" method=\"post\">
	<table>
		<tr>
			<td>介绍:</td>
			<td>
				<textarea name=\"about\" id=\"add_about\" style=\"width: 500px; height:270px\" ><?php echo isset($data[\'content\'])?$data[\'content\']:\'\'?></textarea>
			</td>
		</tr>
	</table>
</form>
< >
$(function(){
	KindEditor. Path = \'<?php echo $cdn_host;?>js/kindeditor-4.1.10/\';
	setTimeout(function(){
		window.editor = KindEditor.create(\'#add_about\', {
			filterMode: false,//是否开启过滤模式
			uploadJson: \'/admin/public/upload?type=imgFile\',
		/*	fileManagerJson: \'?m=upload&f=file_manager_json&is_json=1\',
			allowFileManager: true*/
			afterBlur: function () { this.sync(); }
		});
	},100);
});

//添加,编辑操作
function ydkCourseAddDialogEvt(href){
	//提交表单操作
	 var isValid = $(\'#add_form\').form(\'validate\');
		if (!isValid) {
			return false;
		}
		
	//MaskUtil.mask();	//打开loading效果
	var formData = new FormData($( \"#add_form\" )[0]);

	$.ajax({
		url: href,
		data: formData,
		dataType: \'json\',
		type: \'post\',

		async: false,  
		cache: false,  
		contentType: false,  
		processData: false,
		
		success: function(result) {
			if (result.status == \'success\') {
				dialog(\'close\');	//关闭添加弹出框
				$(\'#easyuiTable\').datagrid(\'reload\');	//根据table的ID刷新easyui表格
			}
		   // MaskUtil.unmask();//关闭loading效果
			M(result.message);	//弹出[错误/正确]信息
		}
	});
}
</ >

 

收藏 打印