Skip to content

Commit be0bcf3

Browse files
committed
doll front
1 parent eb6a367 commit be0bcf3

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

02 - JS + CSS Clock/index.html

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
<title>Document</title>
66
</head>
77
<body>
8-
9-
8+
<div id="demo">
9+
</div>
1010
<div class="clock">
1111
<div class="clock-face">
1212
<div class="hand hour-hand"></div>
1313
<div class="hand min-hand"></div>
1414
<div class="hand second-hand"></div>
15+
<button onclick="postDoll()">Click me</button>
1516
</div>
1617
</div>
1718

1819

1920
<style>
2021
html {
21-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
22+
/*background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);*/
2223
background-size:cover;
2324
font-family:'helvetica neue';
2425
text-align: center;
@@ -89,7 +90,45 @@
8990
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
9091
}
9192

93+
function getDoll(){
94+
var xmlhttp = new XMLHttpRequest();
95+
xmlhttp.onreadystatechange = function() {
96+
if (this.readyState == 4 && this.status == 200) {
97+
myObj = JSON.parse(this.responseText);
98+
document.getElementById("demo").innerHTML = myObj.doll.status;
99+
}
100+
};
101+
xmlhttp.open("GET", "https://jd-api-staging.herokuapp.com/api/v1/dolls/1", true);
102+
xmlhttp.send();
103+
}
104+
105+
function postDoll() {
106+
var xmlhttp = new XMLHttpRequest();
107+
var doll_status = document.getElementById("demo").innerHTML;
108+
109+
xmlhttp.open("PUT", "https://jd-api-staging.herokuapp.com/api/v1/dolls/", false);
110+
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
111+
http.setRequestHeader("Accept", "application/json");
112+
xmlHttpRequest.send(JSON.stringify({
113+
"httpRequest": {
114+
"method": "POST",
115+
"path": "/1",
116+
"body": {
117+
"type": "JSON",
118+
"value": JSON.stringify({
119+
"doll": {
120+
"id": 1,
121+
"status": 2
122+
}
123+
})
124+
}
125+
}
126+
}));
127+
}
128+
92129
setInterval(setDate, 1000);
130+
setInterval(getDoll, 1000);
131+
93132

94133
</script>
95134
</body>

0 commit comments

Comments
 (0)