CKEDITOR不通过AJAX第一次提交提交数据

CKEDITOR不通过AJAX第一次提交提交数据

本文介绍了CKEDITOR不通过AJAX第一次提交提交数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,发展我的应用程序时,我意识到,我的形式不会将数据发送到服务器上的第一个使用CKEDITOR时提交。我点击一次,它会发送空字段没有我输入的但是如果我提交了第二次,它发送的输入数据到服务器。所以,你需要两次提交的数据传递到服务器。

So during development in my application, I realized that my forms are not sending data to the server on the first submit when using CKEDITOR. 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.

有关CKEDITOR,我把它捆绑了BB code插件。

For CKEDITOR, I have it bundled with the BBCODE plugin.

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刀片。

Sorry if the form syntax looks alien to you, it's Laravel Blade.

小结

在第一提交,发送给服务器的数据是空的。在第二提交,事实并非如此。如果您需要了解更多信息,请询问。这不是紧急情况,因为我只是简单地告诉我的用户查看自己的表格,然后重试。

On first submit, the data sent to the server is empty. On the second submit, it is not. If you need more information, please ask. This isn't an emergency because I simply just tell my users to look over their form and try again.

推荐答案

尝试更新CKEditor的相关领域,进行阿贾克斯提交,像以前一样:

try updating the CKEditor related fields, before performing Ajax Submit, like:

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

这篇关于CKEDITOR不通过AJAX第一次提交提交数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:52