// Paste your API Management gateway URL here (see AZURE_SETUP.md, step 8). No trailing slash.
var API_ENDPOINT = "https://employeeapi.azure-api.net/employees";
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 () {
document.getElementById("profileSaved").innerHTML = "Profile Saved!";
},
error: function () {
alert("error");
},
});
};
document.getElementById("getprofile").onclick = function () {
$.ajax({
url: API_ENDPOINT,
type: "GET",
success: function (response) {
$("#employeeProfile tr").slice(1).remove();
jQuery.each(response, function (i, data) {
var row = $("<tr>");
// .text() escapes the value, so stored data can't inject HTML/JS
row.append($("<td>").text(data["empId"]));
row.append($("<td>").text(data["empFirstName"]));
row.append($("<td>").text(data["empLastName"]));
row.append($("<td>").text(data["empAge"]));
$("#employeeProfile").append(row);
});
},
error: function () {
alert("error");
},
});
};