Untitled
unknown
javascript
2 years ago
1.8 kB
7
Indexable
var domain = "http://127.0.0.1:5500/fake-server"; //when the page loads, showcase the data function getEmplFrom(callback) { return new Promise((reject, resolve)=>{ var xhr = new XMLHttpRequest(); xhr.open('GET', domain + "/employees.json"); xhr.onload = function(e) { if (this.status == 200) { reject(e); callback(e); } resolve(e); } xhr.send(); }); } function abRmnSal() { //TODO returns salaries from json var xmlhttp = new XMLHttpRequest(); var url = "http://127.0.0.1:5500/fake-server/salaries.json"; xmlhttp.onload = function() { if (this.readyState == 4 && this.status == 200) { var myArr = JSON.parse(this.responseText); var newArr = []; myArr.forEach(element => { newArr.push(element.salary); }); console.log(newArr) return newArr[0]; } }; xmlhttp.open("GET", url, true); xmlhttp.send(); } function zbir() { return [1,2,3]; } var salaryArr = []; salaryArr = abRmnSal(); console.log(salaryArr) function getEmployees() { //TODO should be exposed function which returns array of employees => for example [{id:"id", "name":"test", "salary":""}] var xmlhttp = new XMLHttpRequest(); var url = "http://127.0.0.1:5500/fake-server/employees.json"; xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var myArr = JSON.parse(this.responseText); var newArr = []; myArr.forEach(element => { newArr.push(element); }); newArr.sort((a, b) => parseFloat(a.id) - parseFloat(b.id)); console.log(newArr) for(let i=0; i<newArr.length;i++){ newArr[i].salary = salaryArr[0]; } console.log(newArr) return newArr; } }; xmlhttp.open("GET", url, true); xmlhttp.send(); }
Editor is loading...