Backend Dag 7 Frontend.pdf
1.9 MB
Backend Dag 8 Frontend Forts.pdf
2.4 MB

<script>
function fetchAuth () {
// (A) URL & CREDENTIALS
var url = "http://localhost:4000/users",
credentials = "testa";
// (B) FETCH WITH HTTP AUTH
fetch (url, {
headers: {
"Authorization": `Basic ${credentials}`
}
})
// (C) SERVER RESPONSE
.then((result) => {
if (result.status != 200) { throw new Error("Bad Server Response"); }
return result.text();
})
.then((response) => {
document.getElementById("demoShow").innerHTML = response;

})
// (D) HANDLE ERRORS (OPTIONAL)
.catch((error) => { console.log(error); });
}

</script>
<div id="demoShow"></div>
<input type="button" value="Fetch Auth" onclick="fetchAuth()"/>

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.