我如何在Laravel刀片文件中显示接收到的多个JSON数据

时间:2019-06-27 10:47:57

标签: json ajax laravel

(路由文件)

Route::post('/report/collectorSearch','reportController@collectorSearch');

(刀片文件) Ajax代码

        $('#collector_name').change(function(event) {
            /* Act on the event */
            var collector_id = $(this).val();

            $.ajax({
                url: '{{URL::to("/report/collectorSearch")}}',
                type: 'POST',
                data: { 
                    collector_id:collector_id,
                    _token: $('#Productsignup_token').val() 
                },
                dataType:'json',

                success:function(CollectorResponse){
                        console.log(CollectorResponse);

                    }
                })

        });

控制器

  public function collectorSearch(Request $request){

        $getCollector_id = $request->collector_id;

        if ($getCollector_id) {
            $searchs = sellproduct::where('collector_id',$getCollector_id)->get();
            return response()->json($searchs);

        }
    }

0 个答案:

没有答案