1. Api Post Put Same plate-form not cross plate-form and
call Api Post using json with body,
call Api Put using json with body,
call Api Delete using json,
call Api Get using json with url,
<script src="~/scripts/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function () {
$("#insert").click(function () {
insert();
})
$("#update").click(function () {
update();
})
})
function insert() {
$.ajax({
type: "post",
url: "http://localhost:52359/api/employees_/",
contentType: "application/json",
dataType: "json",
data: JSON.stringify({
Srno: $("#Srno").val(),
Emp_Name: $("#Emp_Name").val(),
Address: $("#Address").val(),
Mobile: $("#Mobile").val()
}),
success: function (data) {
alert(data);
var dt = JSON.parse(data);
//alert(jsonObj.length);
},
error: function (data) {
alert("error : " + data);
},
failed: function (data) {
alert("failed : " + data);
}
});
}
function update() {
$.ajax({
type: "put",
url: "http://localhost:52359/api/employees_/" + $("#Srno").val(),
contentType: "application/json",
dataType: "json",
data: JSON.stringify({
Srno: $("#Srno").val(),
Emp_Name: $("#Emp_Name").val(),
Address: $("#Address").val(),
Mobile: $("#Mobile").val()
}),
success: function (data) {
alert(data);
var dt = JSON.parse(data);
//alert(jsonObj.length);
},
error: function (data) {
alert("error : " + data);
},
failed: function (data) {
alert("failed : " + data);
}
});
}
</script>
call Api Post using json with body,
call Api Put using json with body,
call Api Delete using json,
call Api Get using json with url,
<script src="~/scripts/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function () {
$("#insert").click(function () {
insert();
})
$("#update").click(function () {
update();
})
})
function insert() {
$.ajax({
type: "post",
url: "http://localhost:52359/api/employees_/",
contentType: "application/json",
dataType: "json",
data: JSON.stringify({
Srno: $("#Srno").val(),
Emp_Name: $("#Emp_Name").val(),
Address: $("#Address").val(),
Mobile: $("#Mobile").val()
}),
success: function (data) {
alert(data);
var dt = JSON.parse(data);
//alert(jsonObj.length);
},
error: function (data) {
alert("error : " + data);
},
failed: function (data) {
alert("failed : " + data);
}
});
}
function update() {
$.ajax({
type: "put",
url: "http://localhost:52359/api/employees_/" + $("#Srno").val(),
contentType: "application/json",
dataType: "json",
data: JSON.stringify({
Srno: $("#Srno").val(),
Emp_Name: $("#Emp_Name").val(),
Address: $("#Address").val(),
Mobile: $("#Mobile").val()
}),
success: function (data) {
alert(data);
var dt = JSON.parse(data);
//alert(jsonObj.length);
},
error: function (data) {
alert("error : " + data);
},
failed: function (data) {
alert("failed : " + data);
}
});
}
</script>
No comments:
Post a Comment