refactor xhr
This commit is contained in:
parent
943c971654
commit
00b356ccf8
4 changed files with 291 additions and 275 deletions
30
7-network/1-xmlhttprequest/example.view/index.html
Normal file
30
7-network/1-xmlhttprequest/example.view/index.html
Normal file
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE HTML>
|
||||
<script>
|
||||
function run() {
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
write(`readyState=${xhr.readyState}`);
|
||||
|
||||
xhr.open('GET', 'digits');
|
||||
write(`readyState=${xhr.readyState}`);
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
write(`readyState=${xhr.readyState}, responseText.length=${xhr.responseText.length}`);
|
||||
};
|
||||
|
||||
xhr.onprogress = function() {
|
||||
write(`readyState=${xhr.readyState}, responseText.length=${xhr.responseText.length}`);
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function write(text) {
|
||||
let li = log.appendChild(document.createElement('li'));
|
||||
li.innerHTML = text;
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick="run()">Load digits</button>
|
||||
|
||||
<ul id="log"></ul>
|
Loading…
Add table
Add a link
Reference in a new issue