Internet-programming-UlSTU/Lab3/js/test.js

31 lines
739 B
JavaScript
Raw Normal View History

2023-11-17 16:53:47 +04:00
const serverUrl = "http://localhost:8081";
let forma = document.querySelector("#for-test");
let val;
function getAllUsers(){
return fetch(`${serverUrl}/users`)
.then((response) => {
return response.json();
});
}
export function testForm(){
let toRet = '';
return getAllUsers().then(res => {
res.forEach((user, index) => {
toRet += user.email;
toRet+=' ';
});
forma.innerHTML += toRet;
});
}
export async function testForm2(){
const res = await fetch(`${serverUrl}/users`);
const data = await res.json();
let toRet = '';
data.forEach((user, index) => {
toRet += user.email;
toRet+=' ';
});
forma.innerHTML += toRet;
}