Last active
May 8, 2018 22:57
-
-
Save RangerDan/08eb9760920d894e144973a2897f1968 to your computer and use it in GitHub Desktop.
Sample HTML page that loads a resource with a button click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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