小编car*_*arl的帖子

在 Laravel 4 中等待控制器时显示进度

我有一个表单,我想通过 ajax-post 发送给我的控制器。同时 HTML 正在等待记录的生成和保存,我想显示进度(现在只是数字)。我真的不明白为什么下面的代码没有<div id="progress">Session::get('progress').

控制器:

public function postGenerate() {
    // getting values from form (like $record_num)
    Session::flash('progress', 0);
    $i = 1;
    for ($i; $i < $record_num; $i++) {
        $record = new Record();
        // adding attributes...
        $record->save;
        Session::flash('progress', $i);
    }
    $response = Response::make();
    $response->header('Content-Type', 'application/json');
    return $response;
}
Run Code Online (Sandbox Code Playgroud)

Javascript:

@section('scripts')
<script type="text/javascript">
    $(document).ready(function() {
        $('#form-overview').on('submit', function() {
            setInterval(function(){
                $('#progress').html( "{{ Session::get('progress') }}" );
            }, 1000);
            $.post(
                $(this).prop('action'),
                {"_token": $(this).find('input[name=_token]').val()},
                function() {
                    window.location.href = 'success';
                }, …
Run Code Online (Sandbox Code Playgroud)

ajax progress laravel

5
推荐指数
1
解决办法
8631
查看次数

标签 统计

ajax ×1

laravel ×1

progress ×1