js
(function($, undefined){ $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); $('#lg-search').on('click', function () { var token = $('meta[name="csrf-token"]').attr('content'); $.ajax({ //На этой строке ошибка filter.js: 27 method: 'post', url: 'treatment', dataType: 'json', data: { "_method": "POST", "_token": token, message: "Answer from ajax" }, success: function (response) { console.log("Response: " + response) }, error: function (data) { console.log("Error: " + data) } }); }); route
Route::post('/treatment', 'FilterController@treatment')->name('treatment'); controller
/** * Display a listing of the resource. * * @param \Illuminate\Http\Request $request * @return Response */ public function treatment(Request $request) { if(Request::ajax()){ return response()->json($request['message'], 201); } } throws error:
jquery.min.js:4 POST https://домен.ru/treatment 500 () send @ jquery.min.js:4 ajax @ jquery.min.js:4 (anonymous) @ filter.js:27 //В этой строчке - $.ajax({ и все dispatch @ jquery.min.js:3 q.handle @ jquery.min.js:3 Please tell me what could be the problem? PS I use Laravel 5.4