-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
133 lines (119 loc) · 2.88 KB
/
test.html
File metadata and controls
133 lines (119 loc) · 2.88 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
// Created by Aaron Knoll
// Licensed under the GNU GPLv3
// (a copy of which is contained along with this application)
$(function(){
const host = "localhost";
$("#POST-button").click(function() {
$.post(`http://${host}/php-crud-api/products/`,
{
"entries": 2,
"product": [
{
"name": "jack",
"price": "3.29"
},
{
"name": "jill",
"price": "4.32"
}
]
}).always(function(data, status) {
$("#POST-response").html(JSON.stringify(data, undefined, 2) + "<br>status: " + status);
});
});
$("#GET-button").click(function() {
const id = "2";
const name = "jack";
const priceLow = "3.29";
const priceHigh = "4.37";
$.get(`http://${host}/php-crud-api/products/?name=${name}&price-low=${priceLow}&price-high=${priceHigh}`,
{dataType: "json"})
.always(function (data, status) {
$("#GET-response").html(JSON.stringify(data, undefined, 2) + "<br>status: " + status);
});
});
$("#PUT-button").click(function() {
$.ajax({
url: `http://${host}/php-crud-api/products/`,
method: "PUT",
// dataType: "json",
data:
{
"entries": 2,
"product": [
{
"id": "366",
"name": "jack",
"price": "2.24"
},
{
"id": "417",
"name": "josephine",
"price": "3.33"
}
]
},
success: function(data, status) {
$("#PUT-response").html(JSON.stringify(data, undefined, 2) + "<br>status: " + status);
},
error: function(data, status) {
alert(JSON.stringify(data));
}
});
});
$("#DELETE-button").click(function() {
const id = "3";
const name = "jill";
const priceLow = "2.49";
const priceHigh = "5.31";
$.ajax({
url: `http://${host}/php-crud-api/products/${id}?name=${name}&price-low=${priceLow}&price-high=${priceHigh}`,
method: "DELETE",
success: function(data, status) {
$("#DELETE-response").html(JSON.stringify(data, undefined, 2) + "<br>status: " + status);
},
error: function(data, status) {
alert(JSON.stringify(data));
}
});
});
});
</script>
<style>
html, body {
height: 100%;
padding: 0;
margin: 0;
}
div {
width: 50%;
height: 50%;
float: left;
}
</style>
</head>
<body>
<!-- <pre id="POST-response"></pre> -->
<div id="upper-left">
<button id="POST-button">Send POST request</button>
<pre id="POST-response"></pre>
</div>
<div id="upper-right">
<button id="GET-button">Send GET request</button>
<pre id="GET-response"></pre>
</div>
<div id="lower-left">
<button id="PUT-button">Send PUT request</button>
<pre id="PUT-response"></pre>
</div>
<div id="lower-right">
<button id="DELETE-button">Send DELETE request</button>
<pre id="DELETE-response"></pre>
</div>
</body>
</html>