javascript - CKEDITOR 在第一次提交时不通过 ajax 提交数据

标签 javascript php jquery ajax forms

当使用 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/

相关文章:

javascript - 扩展 JavaScript 对象函数

javascript - 具有多个选择器的事件 - 如何获得触发选择器?

javascript - 根据媒体查询更改 window.scroll 位置?

php - Symfony 2 BlueImp OneupUploaderBundle sql 错误 PostPersistEvent 不工作

php - 如何在 GoDaddy 网站上正确使用 session_start()

jquery - Sortable & droppable, droppable 不会更新,当 DOM 更新时?

javascript - 如何从文本区域中选择某些内容。创建我的编辑器

javascript - 如何在 Javascript 中收集匿名对象垃圾?

javascript - Bootstrap 3.3.7 按钮组 - 只能点击 1 个按钮

php - 获取其中一列值小于集合中感兴趣行的最后一行