-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path4-xhr.html
More file actions
21 lines (18 loc) · 412 Bytes
/
Copy path4-xhr.html
File metadata and controls
21 lines (18 loc) · 412 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<body>
<div id="message"></div>
<script>
const message = document.getElementById('message');
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
message.innerHTML = xhr.status === 200 ?
xhr.responseText : `Error code: ${xhr.status}`;
}
};
xhr.open('GET', '/person', true);
xhr.send();
</script>
</body>
</html>