-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (39 loc) · 1.27 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
document.getElementById('button').addEventListener('click', loadData);
function loadData() {
const xhr = new XMLHttpRequest();
// console.log('READYSTATE', xhr.readyState);
xhr.open('GET', 'data.txt', true);
// console.log('READYSTATE', xhr.readyState);
xhr.onprogress = function() {
console.log('READYSTATE', xhr.readyState);
}
xhr.onload = function(){
console.log('READYSTATE', xhr.readyState);
if(this.status === 200){
// console.log(this.responseText);
document.getElementById('output').innerHTML = `
<h1>${this.responseText}</h1>
`
}
}
// xhr.onreadystatechange = function(){
// console.log('READYSTATE', xhr.readyState);
// if(this.status === 200 && this.readyState === 4) {
// console.log(this.responseText)
// }
// }
xhr.onerror = function() {
console.log('Request error...');
}
xhr.send();
}
// readyState Values
// 0: request not initiated
// 1: server connection established
// 2: request received
// 3: processing request
// 4: request finished and response is ready
// HTTP Statuses
// 200: "OK"
// 403: "Forbidden"
// 404: "Not Found"