HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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;
    }
}