Error Ajax and Laravel 500 (Internal Sever Error) Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Error Ajax and Laravel 500 (Internal Sever Error) without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m attempting to use AJAX in Chrome, but it’s not working. This is my code, which you can see below. This is a copy of my web.php file.

Route::view('menu','',['categories'=> AppCategories::orderBy('name')->get()->take(11),'active' => 'menu'])->name('menu');

This is my ajax

      type: "GET",
      url: "{{url('/products')}}",
      data: "cat_id="+ id,
      success: function(response){
      error: function(data) {
        console.log('Error:', data);

This is the code for my controller method.

    public static function getproducts(Request $request)
        get productsd = $request->cat_id;
        $categories = Categories::orderBy('name')->get()->take(11);
        $collection = DB::table('products')
                      ->join('product_category', '','=', 'product_category.product_id')
                      ->where('product_category.category_id', '=', $category_id)
        return view('',[
            'data' => $collection,
FacadeIgnitionExceptionsViewException: Undefined variable: categories (View: /Applications/XAMPP/xamppfiles/htdocs/shop/resources/views/home/menu.blade.php) in file /Applications/XAMPP/xamppfiles/htdocs/shop/resources/views/home/menu.blade.php on line 28


One change you can do is in "cat_id="+ id, better to pass data: {cat_id:id}

you are not using received category id from request in your query

while returning view ,you are not passing categories

return view('',[
            'data' => $collection,
We are here to answer your question about Error Ajax and Laravel 500 (Internal Sever Error) - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji