-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestapi.php
More file actions
78 lines (67 loc) · 2.85 KB
/
testapi.php
File metadata and controls
78 lines (67 loc) · 2.85 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
<!DOCTYPE html>
<html>
<head>
<script src="assets/jquery-3.2.1.js"></script>
</head>
<body>
<div>
<form action='http://localhost/php_rest_api/api.php' method='POST'>
<h3>Add department using API-POST</h3>
<input type="text" placeholder="Department Name" name="department_name">
<button type="submit">Add</button>
</form>
</div>
<br>
<div>
<form action='http://localhost/php_rest_api/api.php' method='GET'>
<h3>Get department(s) using API-GET</h3>
<input type="text" placeholder="Id of department" name="department_id">
<button type="submit">GET ELEMENT</button>
</form>
</div>
<br>
<div>
<form action="#">
<h3>Update department using API-PUT</h3>
<input type="text" name="id_dpto" placeholder="Id of department">
<input type="text" name="department" placeholder="Department">
<input type="button" value="PUT" name="updateDpto">
</form>
</div>
<br>
<div>
<form action="#">
<h3>Delete department using API-DELETE</h3>
<input type="text" name="id_dpto_delete" placeholder="Id of department">
<input type="button" value="DELETE" name="deleteDpto">
</form>
</div>
<script type="text/javascript">
$('input[name="deleteDpto"]').click(function(){
var dataSend = {department_id: $('input[name="id_dpto_delete"]').val()};
$.ajax({
url: 'http://localhost/php_rest_api/api.php'+ '?' + $.param(dataSend),
type: 'DELETE',
}).done(function(data){
if(data.status === 200){
alert(data.status_message);
} else
alert('Some errors has ocurred. '+ data.status_message);
});
});
$('input[name="updateDpto"]').click(function(){
var dataSend = {department: $('input[name="department"]').val(), department_id: $('input[name="id_dpto"]').val()};
$.ajax({
url: 'http://localhost/php_rest_api/api.php',
type: 'PUT',
data: dataSend
}).done(function(data){
if(data.status === 200){
alert(data.status_message);
} else
alert('Some errors has ocurred. '+ data.status_message);
});
});
</script>
</body>
</html>