-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaxpost.html
78 lines (77 loc) · 2.15 KB
/
ajaxpost.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!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(){
$('textarea').hide();
$('#my-button').click(function(){
let numberInputValue = $('#id-input').val();
let textInputValue = $('#id-text').val();
let bodyInputValue = $('#id-body').val();
console.log('im clicked');
let url = `https://jsonplaceholder.typicode.com/posts`;
$.post(url, {
'title': textInputValue,
'body': bodyInputValue,
'userId': numberInputValue
},
function(data,status) {
if(status === 'success') {
$('textarea').val(JSON.stringify(data));
$('textarea').show();
}
console.log(data);
console.log(status)
});
});
});
</script>
</head>
<body>
<div class="container text-center">
<label for=""
>ID
<input
type="number"
class="form-control"
id="id-input"
placeholder="add id"
min="1"
/>
</label>
<label for=""
>title
<input
type="text"
class="form-control"
id="id-text"
placeholder="add title"
/>
</label>
<label for=""
>body
<input
type="text"
class="form-control"
id="id-body"
placeholder="add body"
/>
</label>
<button class="btn btn-primary" type="button" id="my-button">
Button
</button>
<textarea name="" id="" cols="30" rows="10"></textarea>
</div>
</body>
</html>