-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
59 lines (57 loc) · 1.42 KB
/
demo.html
File metadata and controls
59 lines (57 loc) · 1.42 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WordPress REST API Demo</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background: #f5f5f5;
}
#quote-box {
background: white;
padding: 20px 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
max-width: 500px;
text-align: center;
}
button {
margin-top: 20px;
padding: 10px 20px;
border: none;
background: #0073aa;
color: white;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="quote-box">
<h2>Random Quote</h2>
<p id="quote">Loading...</p>
<button onclick="fetchQuote()">Get New Quote</button>
</div>
<script>
async function fetchQuote() {
try {
const response = await fetch('http://your-site.com/wp-json/quote-api/v1/quotes');
const data = await response.json();
document.getElementById('quote').innerText = data.quote;
} catch (error) {
document.getElementById('quote').innerText = 'Error fetching quote.';
console.error(error);
}
}
// Fetch on page load
window.onload = fetchQuote;
</script>
</body>
</html>