Hello. I can not create a working ajax request.
Here is my code:
Button:
<input type="button" id='{{$contractor->id}}' value="Add to favorites" class="btn btn-success" onclick="addToFavourite(this.id)"/> Js:
function addToFavourite(id) { var base_url = 'http://localhost:8000/' $.ajax({ url: base_url+"add-to-favourite", cache: false, data: {'id': id}, // если нужно передать какие-то данные type: "POST", // устанавливаем типа запроса POST success: function (data) { alert('ok') } //контент подгружается в div#content }); } Route:
Route::post('add-to-favourite', 'ContractorsPage@addToFavourite'); And controller:
class ContractorsPage extends Controller { public function addToFavourite(Request $request){ if($request->ajax()) { $data = Input::all(); print_r($data); die; } dd('ok'); } } From the button in js id is transmitted, through the alert checked, but further ajax request nothing happens. Please tell me what I was wrong.
Error where in url, as debugger reports:
POST http: // localhost: 8000 / add-to-favorite 500 (Internal Server Error)
APP_DEBUG=truein the file.env- xEdelweiss