Javascript Laravel Ajax提交多行数据

Javascript Laravel Ajax提交多行数据,javascript,php,ajax,laravel,laravel-5,Javascript,Php,Ajax,Laravel,Laravel 5,我正在通过Ajax对海量数据进行新的reg处理 Laravel 5.7.28 PHP 7.2版 ■ 按图像右侧的+按钮添加项目 有时无法发送行数据 经过我的检查, 如果提交项目为166或更少,则没有问题,当提交项目为167或更多时发出错误消息。 我不知道是什么问题,请告诉我怎么解决 提交项目为166或更少 提交项目167或更多。 关联代码 路线 Route::resource('ajax-crud', 'AjaxCrudController'); namespace App\Http\C

我正在通过
Ajax
对海量数据进行新的reg处理

Laravel 5.7.28

PHP 7.2版

■ 按图像右侧的+按钮添加项目

有时无法发送行数据

经过我的检查,

如果提交项目为166或更少,则没有问题,当提交项目为167或更多时发出错误消息。 我不知道是什么问题,请告诉我怎么解决

提交项目为166或更少

提交项目167或更多。

关联代码

路线

Route::resource('ajax-crud', 'AjaxCrudController');
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\AjaxCrud;
use Validator;

class AjaxCrudController extends Controller
{
    //skip...

    /**
     * Store Form view
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('ajax_create_items');
    }

    /**
     * Ajax Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        if(request()->ajax())
        {
        //show request input data
        dd($request->input());
        //create process
        //skip...
        }
    }
    //skip...

}
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel </title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
        <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
        <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>  
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    </head>
    <body>

        <div class="container-fluid">

            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading"><h3 class="panel-title">Add Items</h3></div>
                        <div class="panel-body">

                            <form name="add_item" id="add_item" class="form-inline">
                                {{ csrf_field() }}

                                <div class="form-group">
                                    <label for="pr_form_number">PR Form Number: </label>
                                    <input type="text" class="form-control" name="pr_number" value="" readonly required><br><br>
                                </div>

                                <div class="table-responsive">
                                    <table class='table table-bordered table-hover' id="tab_logic">
                                        <thead>
                                            <tr class='info'>
                                                <th style='width:10%;'>ITEM NO.</th>
                                                <th style='width:10%;'>QTY</th>
                                                <th style='width:10%;'>UNIT</th>
                                                <th style='width:30%;'>DESCRIPTION</th>
                                                <th style='width:10%;'>COST PER UNIT</th>
                                                <th style='width:10%;'>COST PER ITEM</th>
                                                <th style='width:10%;'>ACTION</th>
                                            </tr>
                                        </thead>
                                        <thead>
                                            <tr id="addr0">
                                                <td class="custom-tbl"><input class='form-control input-sm'style='width:100%;' type="text" value="1" id="pr_item0" name="pr_item[]" readonly required></td>
                                                <td class="custom-tbl"><input class='form-control input-sm' style='width:100%;' type="text" id="pr_qty0" oninput='multiply(0);' name="pr_qty[]"></td>
                                                <td class="custom-tbl"><input class='form-control input-sm' style='width:100%;' type="text" id="pr_unit0" name="pr_unit[]"></td>
                                                <td class="custom-tbl"><input class='form-control input-sm' style='width:100%;' type="text" id="pr_desc0" name="pr_desc[]"></td>
                                                <td><input class='form-control input-sm' style='width:100%;' type="text" id="pr_cpu0" oninput='multiply(0);' name="pr_cpu[]"></td>
                                                <td class="custom-tbl"><input class='estimated_cost form-control input-sm' id="pr_cpi0" style='width:100%;' type="text" name="pr_cpi[]" readonly></td>
                                                <td class="custom-tbl"><button type="button" id="add" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-plus"></span></button></td>
                                            </tr>
                                        </thead>
                                        <tbody id="dynamic_field">

                                        <tbody>
                                        <tfoot>
                                            <tr class='info'>
                                                <td style='width:65%;text-align:right;padding:4px;' colspan='5'>GRAND TOTAL:</td>
                                                <td style='padding:0px;'>

                                                    <input style='width:100%;' type='text' class='form-control input-sm' id='grand_total' name='grand_total' value='0' readonly required>

                                                </td>

                                        </tfoot>

                                    </table>
                                </div>


                                <button type="button" id="submit" name="submit" class="btn btn-default">Submit</button>
                            </form>

                        </div>

                    </div>
                </div>

            </div>


        </div>

        <script type="text/javascript">



$(document).ready(function () {
    var i = 1;


    $('#add').click(function () {
        i++;
        $('#dynamic_field').append('<tr id="row' + i 
                + '" class="dynamic-added"><td class="custom-tbl"><input id="pr_item' + i 
                + '" class="form-control input-sm"style="width:100%;" type="text" value="' + i 
                + '" name="pr_item[]" readonly required></td><td class="custom-tbl"><input id="pr_qty' + i 
                + '"class="form-control input-sm" style="width:100%;" type="text" oninput="multiply(' + i 
                + ');" name="pr_qty[]"></td><td class="custom-tbl"><input id="pr_unit' + i 
                + '"class="form-control input-sm" style="width:100%;" type="text" name="pr_unit[]"></td><td class="custom-tbl"><input id="pr_desc' + i 
                + '" class="form-control input-sm" style="width:100%;" type="text" name="pr_desc[]"></td><td class="custom-tbl"><input id="pr_cpu' + i 
                + '" class="form-control input-sm" style="width:100%;" type="text" oninput="multiply(' + i 
                + ');" name="pr_cpu[]"></td><td class="custom-tbl"><input id="pr_cpi' + i 
                + '" class="estimated_cost form-control input-sm" style="width:100%;" type="text" name="pr_cpi[]" readonly></td><td class="custom-tbl"><button type="button" name="remove" id="' + i 
                + '" class="btn btn-danger btn-sm btn_remove"><span class="glyphicon glyphicon-remove"></span></button></td></tr>');
    });


    $(document).on('click', '.btn_remove', function () {
        var button_id = $(this).attr("id");
        $('#row' + button_id + '').remove();
    });

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });


    $('#submit').click(function () {
        $.ajax({
            url: "{{route('ajax-crud.store')}}",
            method: "POST",
            data: $('#add_item').serialize(),
            type: 'json',

        });
    });

});




        </script>

        <script type="text/javascript">
            function multiply(id)
            {
                var total1 = parseFloat($('#pr_qty' + id).val()) * parseFloat($('#pr_cpu' + id).val());
                $("input[id=pr_cpi" + id + "]").val(total1);
                grandTotal();
            }
            function grandTotal()
            {
                var items = document.getElementsByClassName("estimated_cost");
                var itemCount = items.length;
                var total = 0;
                for (var i = 0; i < itemCount; i++)
                {
                    total = total + parseFloat(items[i].value);
                }
                document.getElementById('grand_total').value = total;
            }
        </script>

    </body>
</html>
控制器
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\AjaxCrud;
use Validator;

class AjaxCrudController extends Controller
{
    //skip...

    /**
     * Store Form view
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('ajax_create_items');
    }

    /**
     * Ajax Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        if(request()->ajax())
        {
        //show request input data
        dd($request->input());
        //create process
        //skip...
        }
    }
    //skip...

}
ajax\u创建项目。blade

Route::resource('ajax-crud', 'AjaxCrudController');
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\AjaxCrud;
use Validator;

class AjaxCrudController extends Controller
{
    //skip...

    /**
     * Store Form view
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('ajax_create_items');
    }

    /**
     * Ajax Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        if(request()->ajax())
        {
        //show request input data
        dd($request->input());
        //create process
        //skip...
        }
    }
    //skip...

}
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel </title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
        <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
        <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>  
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    </head>
    <body>

        <div class="container-fluid">

            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading"><h3 class="panel-title">Add Items</h3></div>
                        <div class="panel-body">

                            <form name="add_item" id="add_item" class="form-inline">
                                {{ csrf_field() }}

                                <div class="form-group">
                                    <label for="pr_form_number">PR Form Number: </label>
                                    <input type="text" class="form-control" name="pr_number" value="" readonly required><br><br>
                                </div>

                                <div class="table-responsive">
                                    <table class='table table-bordered table-hover' id="tab_logic">
                                        <thead>
                                            <tr class='info'>
                                                <th style='width:10%;'>ITEM NO.</th>
                                                <th style='width:10%;'>QTY</th>
                                                <th style='width:10%;'>UNIT</th>
                                                <th style='width:30%;'>DESCRIPTION</th>
                                                <th style='width:10%;'>COST PER UNIT</th>
                                                <th style='width:10%;'>COST PER ITEM</th>
                                                <th style='width:10%;'>ACTION</th>
                                            </tr>
                                        </thead>
                                        <thead>
                                            <tr id="addr0">
                                                <td class="custom-tbl"><input class='form-control input-sm'style='width:100%;' type="text" value="1" id="pr_item0" name="pr_item[]" readonly required></td>
                                                <td class="custom-tbl"><input class='form-control input-sm' style='width:100%;' type="text" id="pr_qty0" oninput='multiply(0);' name="pr_qty[]"></td>
                                                <td class="custom-tbl"><input class='form-control input-sm' style='width:100%;' type="text" id="pr_unit0" name="pr_unit[]"></td>
                                                <td class="custom-tbl"><input class='form-control input-sm' style='width:100%;' type="text" id="pr_desc0" name="pr_desc[]"></td>
                                                <td><input class='form-control input-sm' style='width:100%;' type="text" id="pr_cpu0" oninput='multiply(0);' name="pr_cpu[]"></td>
                                                <td class="custom-tbl"><input class='estimated_cost form-control input-sm' id="pr_cpi0" style='width:100%;' type="text" name="pr_cpi[]" readonly></td>
                                                <td class="custom-tbl"><button type="button" id="add" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-plus"></span></button></td>
                                            </tr>
                                        </thead>
                                        <tbody id="dynamic_field">

                                        <tbody>
                                        <tfoot>
                                            <tr class='info'>
                                                <td style='width:65%;text-align:right;padding:4px;' colspan='5'>GRAND TOTAL:</td>
                                                <td style='padding:0px;'>

                                                    <input style='width:100%;' type='text' class='form-control input-sm' id='grand_total' name='grand_total' value='0' readonly required>

                                                </td>

                                        </tfoot>

                                    </table>
                                </div>


                                <button type="button" id="submit" name="submit" class="btn btn-default">Submit</button>
                            </form>

                        </div>

                    </div>
                </div>

            </div>


        </div>

        <script type="text/javascript">



$(document).ready(function () {
    var i = 1;


    $('#add').click(function () {
        i++;
        $('#dynamic_field').append('<tr id="row' + i 
                + '" class="dynamic-added"><td class="custom-tbl"><input id="pr_item' + i 
                + '" class="form-control input-sm"style="width:100%;" type="text" value="' + i 
                + '" name="pr_item[]" readonly required></td><td class="custom-tbl"><input id="pr_qty' + i 
                + '"class="form-control input-sm" style="width:100%;" type="text" oninput="multiply(' + i 
                + ');" name="pr_qty[]"></td><td class="custom-tbl"><input id="pr_unit' + i 
                + '"class="form-control input-sm" style="width:100%;" type="text" name="pr_unit[]"></td><td class="custom-tbl"><input id="pr_desc' + i 
                + '" class="form-control input-sm" style="width:100%;" type="text" name="pr_desc[]"></td><td class="custom-tbl"><input id="pr_cpu' + i 
                + '" class="form-control input-sm" style="width:100%;" type="text" oninput="multiply(' + i 
                + ');" name="pr_cpu[]"></td><td class="custom-tbl"><input id="pr_cpi' + i 
                + '" class="estimated_cost form-control input-sm" style="width:100%;" type="text" name="pr_cpi[]" readonly></td><td class="custom-tbl"><button type="button" name="remove" id="' + i 
                + '" class="btn btn-danger btn-sm btn_remove"><span class="glyphicon glyphicon-remove"></span></button></td></tr>');
    });


    $(document).on('click', '.btn_remove', function () {
        var button_id = $(this).attr("id");
        $('#row' + button_id + '').remove();
    });

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });


    $('#submit').click(function () {
        $.ajax({
            url: "{{route('ajax-crud.store')}}",
            method: "POST",
            data: $('#add_item').serialize(),
            type: 'json',

        });
    });

});




        </script>

        <script type="text/javascript">
            function multiply(id)
            {
                var total1 = parseFloat($('#pr_qty' + id).val()) * parseFloat($('#pr_cpu' + id).val());
                $("input[id=pr_cpi" + id + "]").val(total1);
                grandTotal();
            }
            function grandTotal()
            {
                var items = document.getElementsByClassName("estimated_cost");
                var itemCount = items.length;
                var total = 0;
                for (var i = 0; i < itemCount; i++)
                {
                    total = total + parseFloat(items[i].value);
                }
                document.getElementById('grand_total').value = total;
            }
        </script>

    </body>
</html>

拉维尔
添加项目
{{csrf_field()}}
请购单编号:


项目编号。 数量 单位 描述 单位成本 每项费用 行动 总计: 提交 $(文档).ready(函数(){ var i=1; $('#添加')。单击(函数(){ i++; $(“#动态_字段”)。追加(“”); }); $(文档).on('click','btn_remove',函数(){ var按钮_id=$(this.attr(“id”); $(“#行”+按钮id+”).remove(); }); $.ajaxSetup({ 标题:{ 'X-CSRF-TOKEN':$('meta[name=“CSRF-TOKEN”]).attr('content')) } }); $(“#提交”)。单击(函数(){ $.ajax({ url:“{route('ajax-crud.store')}}”, 方法:“张贴”, 数据:$('#添加项')。序列化(), 键入:“json”, }); }); }); 函数乘法(id) { var total1=parseFloat($('pr#u qty'+id).val())*parseFloat($('pr#u cpu'+id).val()); $(“输入[id=pr_cpi”+id+“]”)val(总计1); grandTotal(); } 函数grandTotal() { var items=document.getElementsByClassName(“估计成本”); var itemCount=items.length; var合计=0; 对于(变量i=0;i
您可以发布错误消息吗?还是行错误?请查看
kernel.php
文件。您可以在多长时间内发送多少请求?奇怪的是,没有错误消息,但当你在太短的时间内发送太多的请求时,可能是Laravel在起作用。