Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Safe Browser and Fetch API
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
<title>fetch-app</title>
</head>
<body>
<script>
(function() {
let msg = document.createElement('p')
fetch('resource.json').then( (res) => {
return res.json()
}).then( (data) => {
msg.innerText = data.message
document.body.appendChild(msg)
}).catch( (error) => {
msg.innerText = error.message
document.body.appendChild(msg)
})
}())
</script>
</body>
</html>
{
"message": "Hello World"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.