Internet-programming-UlSTU/Lab3/js/test.js
2023-11-17 16:55:32 +04:00

31 lines
739 B
JavaScript

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;
}