getEmployees().then( response => { console.log(JSON.parse(response)) }) .catch(function(error) { console.error(error); }) function getEmployees() { return new Promise(function(resolve, reject) { let url = "http://localhost:8000/api/employees"; let http = new XMLHttpRequest(); http.open('get', url, true); http.send(); http.onload = function() { if(http.status == 200) { resolve(http.responseText); }else { reject('Hiba! A lekérés sikertelen!') } } http.onerror = function() { reject('Hiba! A hálózat nem elérhető!') } }) }