I'm trying to do a search with AJAX and it says 405 (Method Not Allowed)
.
I do not know what I can be, I tried looking at the routes and I can not find the error.
My AJAX
<script type ="text/javascript">
$(document).ready(function()
{
$.ajaxSetup({
headers:{
'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')
}
});
$('#form').submit(function(e)
{
e.preventDefault();
data = $(this).serialize();
$.post('/getSearch', data, function(search)
{
$('#data').html('');
$.each(search, function (key,val){
$('#data').append('<tr>'+
'<td> '+val.name+'</td>'+
'<td> '+val.address+'</td>'+
'</tr>');
});
});
});
});
</script>
My Controller
class SearchController extends Controller
{
public function index(Request $req)
{
$datas= search::all();
return view ('search', compact ('datas'));
}
public function getSearch (Request $req)
{
if($req->ajax())
{
$find= search::where('name', 'LIKE','%' .$req->search. '%' )->get();
return response()->json($find);
}
}
}
And my routes
//---------------------------------search-----------
Route::get('/search','SearchController@index')->name('index');
Route::get('/getSearch', 'SearchController@getSearch')->name('post');