-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2701.html
More file actions
34 lines (32 loc) · 1.28 KB
/
2701.html
File metadata and controls
34 lines (32 loc) · 1.28 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<p>Check addeventlister and fetch..then..then</p>
<p><button type="button" name="btnsubmit" id="btnsubmit" class="btn btn-primary" btn-lg btn-block">Click me</button></p>
<div id="resultdiv" style="display: none;">Loading...</div>
<script type="application/javascript">
const btn = document.getElementById('btnsubmit');
const resultdiv = document.getElementById('resultdiv');
btn.addEventListener('click',function(){
console.log('btn clicked');
resultdiv.style = "display:block";
fetch("https://dilip-parmar.in/wp-json/wp/v2/opening-time")
.then((data)=>{
return data.json();
}).then((result)=>{
console.log(result);
resultdiv.innerText = result;
}).catch(error=>{
resultdiv.innerText = 'Error: Something went wrong';
console.log('Error: not able to fetch the reques');
console.log(error);
});
});
</script>
</body>
</html>