Show the result in the page
Create elements and use textContent, so data can never run as HTML.
AJAX · Show the result in the pageBeginner
async function showItems() {
const data = await (await fetch('/api/items')).json();
const list = document.getElementById('list');
list.innerHTML = '';
data.items.forEach(function (item) {
const li = document.createElement('li');
li.textContent = 'Item ' + item;
list.appendChild(li);
});
}
showItems();fetchDOMtextContentlist