当使用 CKEDITOR 时,我的表单在第一次提交时没有向服务器发送数据。如果我单击它一次,它会在没有我输入的情况下发送空字段。但是,如果我第二次提交,它会将输入的数据发送到服务器。所以需要提交两次,数据才能传到服务器。
我将 CKEDITOR 与 BBCODE 插件捆绑在一起。
jQuery 技术
$('form#ajax').on('submit', function(){
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value){
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
console.log(data.message); // Outputs on second submit
$.ajax({
url: url,
type: type,
data: data,
success: function(response){
//
}
});
return false;
});
表单
{{ Form::open(array('action' => 'AppsController@sendApp', 'class' => 'app', 'id' => 'ajax')) }}
<div class="form-container">
{{ Form::label('message', 'Application', array('style' => 'padding-top: 5px')) }}
<textarea name="message" cols="50" rows="6" class="form-control" id="eitor" style="padding-top:5px;"></textarea>
</div>
{{ Form::submit('Send Application', array('class' => 'btn btn-core btn-block submit', 'style' => 'margin-top: 5px')) }}
{{ Form::close() }}
抱歉,如果表单语法对您来说看起来很陌生,那是 Laravel Blade。
回顾
第一次提交时,发送到服务器的数据是空的。在第二次提交时,它不是。
最佳答案
尝试在执行 Ajax 提交之前更新 CKEditor 相关字段,例如:
$('form#ajax').on('submit', function(){
for ( instance in CKEDITOR.instances ) {
CKEDITOR.instances[instance].updateElement();
}
//rest of your code
关于javascript - CKEDITOR 在第一次提交时不通过 ajax 提交数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24398225/