updates
This commit is contained in:
parent
94c83e9e50
commit
cc5213b09e
79 changed files with 1341 additions and 357 deletions
42
5-network/08-xmlhttprequest/phones-async.view/index.html
Normal file
42
5-network/08-xmlhttprequest/phones-async.view/index.html
Normal file
|
@ -0,0 +1,42 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<button onclick="loadPhones()" id="button">Load phones.json!</button>
|
||||
|
||||
<script>
|
||||
function loadPhones() {
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', 'phones.json');
|
||||
|
||||
|
||||
xhr.send();
|
||||
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) return;
|
||||
|
||||
button.innerHTML = 'Complete!';
|
||||
|
||||
if (xhr.status != 200) {
|
||||
// handle error
|
||||
alert(xhr.status + ': ' + xhr.statusText);
|
||||
} else {
|
||||
// show result
|
||||
alert(xhr.responseText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
button.innerHTML = 'Loading...';
|
||||
button.disabled = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue