Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 133ba02

Browse files
examples for chapter 2.6 uploaded
examples for chapter 2.6 uploaded
1 parent 63eae75 commit 133ba02

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>onreadystatechange</title>
9+
10+
<script type="text/javascript" src="2.6-onreadystatechange.js"></script>
11+
12+
</head>
13+
14+
<body>
15+
16+
<h1>The XMLHttpRequest Object - onreadystatechange</h1>
17+
18+
<button type="button" onclick="loadData()">Load Content</button>
19+
20+
<div id="textContainer"></div>
21+
22+
</body>
23+
24+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
console.log('2.6-onreadystatechange.js loaded');
2+
3+
function loadData() {
4+
5+
var xhr = new XMLHttpRequest();
6+
xhr.open('GET','data.txt',true);
7+
8+
xhr.onreadystatechange = function() {
9+
if(this.readyState == 4 && this.status == 200) {
10+
// responseText and response both are same/similar
11+
let responseText = xhr.responseText;
12+
let response = xhr.response;
13+
console.log('responseText',responseText);
14+
console.log('response',response);
15+
16+
// document.getElementById("textContainer").innerHTML = this.responseText;
17+
document.getElementById("textContainer").innerText = this.responseText;
18+
19+
}
20+
}
21+
22+
xhr.send();
23+
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
<h3>### 2.6.1. XMLHttpRequest-onreadystatechange property</h3>
3+
4+
<li>The XMLHttpRequest object has a special property called `onreadystatechange`</li>
5+
6+
<li>`onreadystatechange` stores the function that will process the response from the server</li>
7+
8+
<li>The `XMLHttpRequest.onreadystatechange` property stores a function, contains the event handler to be called when the `readystatechange` event is fired, that is every time the `readyState` property of the XMLHttpRequest changes</li>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /