say.html
· 501 B · HTML
Неформатований
<body>
<div id="content"></div>
<script>
const url = new URL('/api/v1/saying', 'https://uapis.cn/');
const res = fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}).then(response => response.json())
.then(data => {
console.log(data);
document.getElementById('content').innerText = data.text;
})
.catch(error => {
console.error('Error fetching data:', error);
});
</script>
</body>
| 1 | <body> |
| 2 | <div id="content"></div> |
| 3 | <script> |
| 4 | const url = new URL('/api/v1/saying', 'https://uapis.cn/'); |
| 5 | const res = fetch(url, { |
| 6 | method: 'GET', |
| 7 | headers: { |
| 8 | 'Content-Type': 'application/json', |
| 9 | }, |
| 10 | }).then(response => response.json()) |
| 11 | .then(data => { |
| 12 | console.log(data); |
| 13 | document.getElementById('content').innerText = data.text; |
| 14 | }) |
| 15 | .catch(error => { |
| 16 | console.error('Error fetching data:', error); |
| 17 | }); |
| 18 | </script> |
| 19 | </body> |