weixin_33725807
2019-09-30 12:50
采纳率: 0%
浏览 31

Laravel Ajax发布数据

I have an eCommerce shop where I have to filter products by its categories.

I have to post an array of all filters in the controller, but I am getting this error

 "message": "",
    "exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
    "file": "C:\\xampp\\htdocs\\web_front\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php",
    "line": 179

Here is my code:

 <script>
    $(document).ready(function () {
        var categories = [];
        $('input[name="cat[]"]').on('change', function (e) {
            e.preventDefault();
            categories = []; // reset
            $('input[name="cat[]"]:checked').each(function()
            {
                categories.push($(this).val());
            });



            $.ajax({

                type:"GET",

                url:'advanced_filter/' + categories,


                success:function(data){

                    console.log(data);
                },
                error: function(xhr,errmsg,err)
                {
                    console.log(xhr.responseText);
                }
            });
        });
    });

</script>

web.php

Route::get('advanced_filter/{filters}', 'HomepageController@advanced_filter')->name('advanced_filter');


 public function advanced_filter($filters)
    {
dd($filters);
}

I am trying to show all the filters, so I can make a query to get all the products based on filters. I have created the script where I get all filters and want to post it in the controller. Please, can you see this? Thank you

图片转代码服务由CSDN问答提供 功能建议

                    

我有一家电子商务商店,必须在其中按类别过滤产品。 </ p>

我必须在控制器中发布所有过滤器的数组,但出现此错误</ p>

 “ message”:“”,
     “ exception”:“ Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException”,
     “ file”:“ C:\\ xampp \\ htdocs \\ web_front \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\ Routing \\ RouteCollection.php”,
     “线”:179
 </ code> </ pre>

 

这是我的代码:</ p>

  <script>
     $(document).ready(function(){
         var Categories = [];
         $('input [name =“ cat []”]')。on('change',function(e){
             e.preventDefault();
             类别= [];  // 重启
             $('input [name =“ cat []”]:checked')。each(function()
             {
                 Categories.push($(this).val());
             });



             $ .ajax({

                 类型:“ GET”,

                 url:'advanced_filter /'+类别,


                 成功:功能(数据){

                     console.log(data);
                 },
                 错误:功能(xhr,errmsg,err)
                 {
                     console.log(xhr.responseText);
                 }
             });
         });
     });

 </ script>
 </ code> </ pre>

 

web.php </ p>

  Route :: get('advanced_filter / {filters}','HomepageController @ advanced_filter')-> name('advanced_filter');


  公共函数advanced_filter($ filters)
     {
 dd($ filters);
 }
 </ code> </ pre>

 

我正在尝试显示所有过滤器,因此我可以进行查询以获取基于过滤器的所有产品。 我创建了一个脚本,在该脚本中我可以获取所有过滤器并将其发布到控制器中。 拜托,你能看到这个吗? 谢谢</ p>      </ div>

1条回答 默认 最新

相关推荐 更多相似问题