vincej
4 months ago
92
10
Laravel

Posting Ajax data to Laravel 5.7 gives JS error 500

Posted 4 months ago by vincej

I need to pass an array back to L5.7 for processing. My Ajax function finds the route and in turn the controller. However, I am having trouble including the data. When I do I get a 500 error back. What in the world am I doing wrong ??

$.ajax(
                    {
                        type: "POST",
                        url: '/newUpdate',
                        data: JSON.stringify(categories),
                        success:function(response) {
                            console.log(response);       // I get a "Hello World response on the console" 
                        }
                    })

Route


Route::post('newUpdate', '[email protected]');  

// THIS DOES NOT HELP, GIVES A 404
Route::post('newUpdate/{categories}', '[email protected]');    

Controller

 public function newUpdate(){

      echo('Hello World');          //THIS WORKS
    
}

 public function newUpdate($catgeories){

      var dump($categories)              //THIS FAILS WITH A 500 ERROR
    
}

Please sign in or create an account to participate in this conversation.