Last active
June 11, 2024 09:52
-
-
Save bdelacretaz/34092425efc3fa4f68467a4d8d2ad11b to your computer and use it in GitHub Desktop.
HTML page that tests Synchronous XHR
This file contains 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> | |
<title>Testing Sync XHR</title> | |
</head> | |
<body> | |
<h1>Testing <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Synchronous_and_Asynchronous_Requests">Sync XHR</a></h1> | |
<div id="msg">This is the msg</div> | |
<pre id="pre">Response comes here.</pre> | |
<script> | |
const msg = document.querySelector('#msg'); | |
const pre = document.querySelector('#pre'); | |
const url = "https://httpbin.org/delay/2"; | |
msg.textContent = `Requesting ${url}`; | |
var request = new XMLHttpRequest(); | |
request.open("GET", url, false); | |
request.send(null); | |
if (request.status === 200) { | |
msg.textContent = `${url} successful`; | |
document.querySelector('#pre').textContent = request.responseText; | |
} else { | |
msg.textContent = `${url} returns ${request.status}`; | |
pre.textContent = 'ERROR'; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can also be tested directly in the Web Console: