-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathscripts.js
More file actions
45 lines (45 loc) · 1.44 KB
/
scripts.js
File metadata and controls
45 lines (45 loc) · 1.44 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
//add your api here below
var API_ENDPOINT = "Paste endpoint URL"
//AJAX GET REQUEST
document.getElementById("saveprofile").onclick = function(){
var inputData = {
"empId":$('#empid').val(),
"empFirstName":$('#fname').val(),
"empLastName":$('#lname').val(),
"empAge":$('#empage').val()
};
$.ajax({
url: API_ENDPOINT,
type: 'POST',
data: JSON.stringify(inputData) ,
contentType: 'application/json; charset=utf-8',
success: function (response) {
document.getElementById("profileSaved").innerHTML = "Profile Saved!";
},
error: function () {
alert("error");
}
});
}
//AJAX GET REQUEST
document.getElementById("getprofile").onclick = function(){
$.ajax({
url: API_ENDPOINT,
type: 'GET',
contentType: 'application/json; charset=utf-8',
success: function (response) {
$('#employeeProfile tr').slice(1).remove();
jQuery.each(response, function(i,data) {
$("#employeeProfile").append("<tr> \
<td>" + data['empId'] + "</td> \
<td>" + data['empFirstName'] + "</td> \
<td>" + data['empLastName'] + "</td> \
<td>" + data['empAge'] + "</td> \
</tr>");
});
},
error: function () {
alert("error");
}
});
}