我有一个包含一些文本字段和textarea(ckeditor)的表单,在onclick按钮art_title字段值发送到art_save.php页面后,但不发送textarea的值。
<script src="ckeditor/ckeditor.js"></script>
function saveArt()
{
var title = document.getElementById('art_title'),
art_title = title.value;
var desc = document.getElementById('art_body'),
art_body = desc.value;
jQuery.ajax({
type: 'POST',
url: 'art_save.php',
data: {
title: art_title,
aut: art_author,
tag: art_tag,
desc: art_body
}
});
return false;
}
html部分
<form method="post" name="art" id="art">
<input type="text" id="art_title" name="art_title" placeholder="Here goes your title"/>
<textarea class="ckeditor" name="art_body" id="art_body"></textarea>
<input type="submit" name="savedraft" id="savedraft" onclick="saveArt();return false;" value="Need more Research ! Save as Draft" class="button"/>
</form>
答案 0 :(得分:25)
您可以强制CKeditor使用以下命令更新textarea值:
for (instance in CKEDITOR.instances) {
CKEDITOR.instances[instance].updateElement();
}
此外,您可以使用.serialize
作为数据 - 如果参数更改,您将不必维护AJAX代码:
<script src="ckeditor/ckeditor.js"></script>
function saveArt()
{
for (instance in CKEDITOR.instances) {
CKEDITOR.instances[instance].updateElement();
}
jQuery.ajax({
type: 'POST',
url: 'art_save.php',
data: $("#art").serialize()
});
return false;
}
答案 1 :(得分:3)
for (instance in CKEDITOR.instances)
{
CKEDITOR.instances[instance].updateElement();
}
$.ajax({
url: "controllers/c.publicidad.php?task=save",
type: 'post',
data: $("form[name='form']").serialize(),
dataType: 'json',
success: function(data) {
if(data.idenvio != ''){
$("form[name='frmPublicidad']").toggle("slow");
$("#MessageSuscripcion").html(data.message);
}
}
});
答案 2 :(得分:0)
你可以用这个获得html表单ckeditor:
var art_body = CKEDITOR.instances.art_body.getData();
答案 3 :(得分:0)
我修复了更改时字段值的更新。这是我的代码:
HTML:
<div class="row">
<div class="form-group col-sm-11">
<label for="ckfield">ckfield</label>
<textarea id="ckfield" class="form-control" rows="10" name="ckfield" cols="50"></textarea>
</div>
</div>
JS:
<script>
$(function(){
var $ckfield = CKEDITOR.replace( 'ckfield' );
$ckfield.on('change', function() {
$ckfield.updateElement();
});
});
</script>