I'mm using laravel 5.4 and I want to create AJAX that can post data to server but I got this error message
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
https://i.stack.imgur.com/gjIbU.png
Here's my AJAX
$('#testAjax').on('click',function(){
$.post('{{ route('edit') }}',{body:'string',_token:'{{ Session::token() }}'},function(data){
console.log(JSON.stringify(data));
});
});
My routes
Route::post('/edit',[ 'uses'=>'AjaxController@getProfessions', 'as'=>'edit']);
My Controller
public function getProfessions(Request $request)
{
$this->validate($request, [
'body' => 'required'
]);
$p = profession::where('categories_id'=>$request['postId']);
return response()->json(['new_body' => 'Server'], 200);
}
Currently I only want response 'Server' from the server instead of 'string' from ajax it self so i know it's coming from server