简体   繁体   English

CKEDITOR在首次提交时不通过ajax提交数据

[英]CKEDITOR doesn't submit data via ajax on first submit

My forms are not sending data to the server on the first submit when using CKEDITOR. 使用CKEDITOR时,我的表单不会在第一次提交时向服务器发送数据。 If I click it once, it sends empty fields without my input. 如果我单击一次,它将发送空字段而不输入。 However, if I submit it a second time, it sends the inputted data to the server. 但是,如果我第二次提交,它会将输入的数据发送到服务器。 So you need to submit it twice for data to be passed to the server. 所以你需要提交两次数据才能传递给服务器。

I have CKEDITOR bundled with the BBCODE plugin. 我有CKEDITOR与BBCODE插件捆绑在一起。

jQuery Ajax jQuery Ajax

$('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 形成

{{ 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() }}

Sorry if the form syntax looks alien to you, it's Laravel Blade. 很抱歉,如果表单语法看起来与你不相同,那就是Laravel Blade。

Recap 概括

On first submit, the data sent to the server is empty. 首次提交时,发送到服务器的数据为空。 On the second submit, it is not. 在第二次提交时,它不是。

try updating the CKEditor related fields, before performing Ajax Submit, like: 在执行Ajax Submit之前尝试更新CKEditor相关字段,如:

$('form#ajax').on('submit', function(){
    for ( instance in CKEDITOR.instances ) {
        CKEDITOR.instances[instance].updateElement();
    }
    //rest of your code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM