-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
68 lines (59 loc) · 1.89 KB
/
index.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
<script src="promiseXHR.js"></script>
</head>
<body>
<h1>Demo using JSONPlaceholder</h1>
<p>See <a href="https://github.com/typicode/jsonplaceholder">https://github.com/typicode/jsonplaceholder</a></p>
<h1>Album Info</h1>
<div id="content"></div>
<h1>Code</h1>
<pre>
var params = {
'albumId': 36,
'id': 1751,
};
var result;
getJSON('https://jsonplaceholder.typicode.com/photos/', {
method: 'GET',
apiquery: params,
})
.then(function (json) {
result = '<b>albumId:</b> ' + json[0].albumId;
result += ' <b>id:</b> ' + json[0].id;
result += '<h2>' + json[0].title + '</h2>';
result += '<img src="' + json[0].thumbnailUrl + '" >';
document.getElementById("content").innerHTML = result;
})
.catch(function (error) {
result = 'API Failure: ' + error.status + ' ' + error.statusText;
document.getElementById("content").innerHTML = result;
});
</pre>
<script>
var params = {
'albumId': 36,
'id': 1751,
};
var result;
getJSON('https://jsonplaceholder.typicode.com/photos/', {
method: 'GET',
apiquery: params,
})
.then(function (json) {
result = '<b>albumId:</b> ' + json[0].albumId;
result += ' <b>id:</b> ' + json[0].id;
result += '<h2>' + json[0].title + '</h2>';
result += '<img src="' + json[0].thumbnailUrl + '" >';
document.getElementById("content").innerHTML = result;
})
.catch(function (error) {
result = 'API Failure: ' + error.status + ' ' + error.statusText;
document.getElementById("content").innerHTML = result;
});
</script>
</body>
</html>