|
5 | 5 | <title>Document</title> |
6 | 6 | </head> |
7 | 7 | <body> |
8 | | - |
9 | | - |
| 8 | +<div id="demo"> |
| 9 | +</div> |
10 | 10 | <div class="clock"> |
11 | 11 | <div class="clock-face"> |
12 | 12 | <div class="hand hour-hand"></div> |
13 | 13 | <div class="hand min-hand"></div> |
14 | 14 | <div class="hand second-hand"></div> |
| 15 | + <button onclick="postDoll()">Click me</button> |
15 | 16 | </div> |
16 | 17 | </div> |
17 | 18 |
|
18 | 19 |
|
19 | 20 | <style> |
20 | 21 | 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);*/ |
22 | 23 | background-size:cover; |
23 | 24 | font-family:'helvetica neue'; |
24 | 25 | text-align: center; |
|
89 | 90 | hourHand.style.transform = `rotate(${hourDegrees}deg)`; |
90 | 91 | } |
91 | 92 |
|
| 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 | + |
92 | 129 | setInterval(setDate, 1000); |
| 130 | + setInterval(getDoll, 1000); |
| 131 | + |
93 | 132 |
|
94 | 133 | </script> |
95 | 134 | </body> |
|
0 commit comments