add API
This commit is contained in:
parent
560c9a69bd
commit
80f9094a91
28
index.html
28
index.html
@ -63,32 +63,4 @@
|
|||||||
<section>Uppgift att lösa!</section>
|
<section>Uppgift att lösa!</section>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
|
||||||
function renderNames(names){
|
|
||||||
let section = document.getElementById('klass');
|
|
||||||
const ul = document.createElement('ul');
|
|
||||||
const fragment = document.createDocumentFragment();
|
|
||||||
|
|
||||||
names.forEach(student => {
|
|
||||||
const li = document.createElement('li');
|
|
||||||
li.innerText = student.name;
|
|
||||||
fragment.appendChild(li);
|
|
||||||
});
|
|
||||||
|
|
||||||
ul.appendChild(fragment);
|
|
||||||
section.appendChild(ul)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getNames(){
|
|
||||||
const response = await fetch('./api/getNames.js');
|
|
||||||
const names = await response.json();
|
|
||||||
|
|
||||||
renderNames(names);
|
|
||||||
|
|
||||||
for(let i = 0; i <names.length; i++){
|
|
||||||
console.log("namn:" + names[i].name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getNames();
|
|
||||||
</script>
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user