I'm using Laravel 5 and I'm doing some filters on some collections in my controller. The problem is using AJAX to be the bridge between the blade template and Controller. Here is my jQuery code:
function listCreatedBy(str) {
$.ajax({
headers : {
'csrftoken' : '{{ csrf_token() }}'
},
url: '{{ url("search") }}',
type: "get", //send it through get method
data:{txt:str},
success: function(response) {
console.log("ola");
$('#results').html(response);
},
error: function(xhr) {
console.log(xhr);
}
});
}
Here is my route:
Route::get('/search/{txt}', 'PrestashopController@search')->name('search');
And here is my method in the controller:
public function search($searchText){
var_dump($searchText);
return "results"; //Just to see if it's returning correctly
}
This method is empty for now because I only want to see if I can complete the ajax code first. But it's returning a 404 code, Not Found. Any idea what I'm doing wrong?