-
-
Save akhyaruu/ca9c5bd43cefd16e0a8a1b7279ad67b9 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Index</title> | |
</head> | |
<body> | |
<button id="button">Dapatkan text file</button> | |
<br> | |
<div id="text"></div> | |
<script> | |
document.getElementById('button').addEventListener('click', loadText); | |
function loadText() { | |
let xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'sample.txt', true); | |
xhr.onload = function () { | |
if (this.status == 200) { | |
document.getElementById('text').innerHTML = this.responseText; | |
} else if (this.status == 404) { | |
document.getElementById('text').innerHTML = 'Not Found'; | |
} | |
} | |
xhr.send(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment