Skip to content

Commit f9961cc

Browse files
committed
JavaScript Promises
1 parent 7af68a6 commit f9961cc

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
<title>&#x1F3F4;&#x200D;&#x2620;&#xFE0F; Complete Javascripts Course</title>
8+
<!-- Latest compiled and minified CSS -->
9+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
10+
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
11+
<style>
12+
13+
</style>
14+
</head>
15+
16+
<body>
17+
<br />
18+
<br />
19+
<center>
20+
<br />
21+
<div id="wrapper">&#x1F4C3; &#x1F3EA; 👾</div>
22+
<div id="output">Complete JavaScript Course</div>
23+
<br />
24+
<div></div>
25+
</center>
26+
<script>
27+
function getData(url) {
28+
return new Promise(function (response) {
29+
var xhr = new XMLHttpRequest();
30+
xhr.open("GET", url);
31+
xhr.onload = function () {
32+
if (xhr.status == 200) {
33+
response(xhr.response);
34+
}
35+
}
36+
xhr.send();
37+
})
38+
}
39+
getData('https://api.myjson.com/bins/snnh5').then(function (response) {
40+
console.log(response);
41+
})
42+
</script>
43+
44+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
45+
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
46+
</script>
47+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
48+
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
49+
</script>
50+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
51+
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
52+
</script>
53+
</body>
54+
55+
</html>

0 commit comments

Comments
 (0)