File: D:/HostingSpaces/SBogers10/vanderkampen.komma.pro/resources/assets/js/site/searchHandler.js
class searchHandler {
constructor(searchUrl) {
console.debug('searchHandler initialized with searchUrl: '+searchUrl);
this.searchUrl = searchUrl;
}
search(term, page = 1, amount = 10) {
if(term === "") return;
self = this;
$.ajax({
type: "GET",
url: this.searchUrl,
data: {
page: page,
amount: amount,
term: term
},
success: function (response) {
self.processSearchResponse(response);
},
error: function () {
console.log("An error occured while searching")
},
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
dataType: 'json'
});
}
processSearchResponse(response)
{
if(!searchHandler.validateSearchResponse(response)) return;
console.log(response);
}
static validateSearchResponse(response)
{
if(
response.hasOwnProperty('data') &&
response.hasOwnProperty('meta')
) return true;
console.error('Search response was not valid');
console.log(response);
return false;
}
}