const href = window.location.href;
const url = href.substring(0, href.lastIndexOf('/')) + "/api/api.php/user";
const form = document.forms[0];

form.addEventListener('submit', function(e) {
    e.preventDefault();

    fetch(url, {
        method: 'GET'
    })
        .then(response => {
            if (response.status === 200) {
                return response.json();
            } else {
                throw new Error('Something went wrong on api server!');
            }
        })
        .then(data => {
            const index = data.findIndex((e) => e.login == form.elements.login.value);
        }).catch(error => {
            console.error(error);
        });
});