-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax1.html
51 lines (50 loc) · 1.5 KB
/
ajax1.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ajax</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js">
</script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script>
$(document).ready(function(){
$('#my-button').click(function(){
let url = `https://jsonplaceholder.typicode.com/todos`
$.get(url,
function(data,status){
if(status == 'success'){
$('body').append(
`<table id="my-table" class="table table-striped">
<tr>
<th>UserId</th>
<th>id</th>
<th>title</th>
<th>completed</th>
</tr>
</table>`);
data.forEach(function(item){
$('#my-table').append(
`<tr>
<td>${item.userId}</td>
<td>${item.id}</td>
<td>${item.title}</td>
<td>${item.completed}</td>
</tr>`)
});
}
});
});
});
</script>
</head>
<body>
<div class="container text-center">
<button id="my-button" class="btn btn-primary mt-5 mb-2">
Click Me To Get DATA
</button>
</div>
</body>
</html>