Skip to content

Instantly share code, notes, and snippets.

@RangerDan
Last active May 8, 2018 22:57
Show Gist options
  • Save RangerDan/08eb9760920d894e144973a2897f1968 to your computer and use it in GitHub Desktop.
Save RangerDan/08eb9760920d894e144973a2897f1968 to your computer and use it in GitHub Desktop.
Sample HTML page that loads a resource with a button click
<html>
<body>
<span class="button">Click Here To Load Content</span>
<pre id="mockedContent">
Content goes here
</pre>
<script>
function loadMock() {
fetch('http://mockedContent.danlearnsstuff.com')
.then((resp) => {
return resp.json();
})
.then((json) => {
document.getElementById("mockedContent").innerHTML=JSON.stringify(json,null,2);
});
}
document.querySelector('.button').addEventListener('click', function () {
loadMock();
alert('you clicked the button.');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment