Demo of CRUD operations from AJAX (Asynchronous JavaScript and XML) with the help of jQuery
-
Run the backend
-
Open
index.html
and click on particular operations -
Refer
console
for details of both working and code
-
NOTE:
- Create
- Read
- Update
- Delete
function create_() {
$.ajax({
type: "POST",
url: URL,
contentType: "application/json",
data: JSON.stringify(DATA1),
success: function () {
var msg = "create successful";
console.log(msg);
htmlOutput(msg);
},
});
}
function read_all() {
$.ajax({
type: "GET",
url: URL,
success: function (data) {
console.log("success!");
console.log(data);
htmlOutput(data);
},
});
}
function read_one() {
$.ajax({
type: "GET",
url: URL,
success: function (data) {
$.each(data, function (index, element) {
console.log("success!");
htmlOutput(element.name);
});
},
});
}
function update_() {
$.ajax({
type: "PUT",
url: URL + ID,
contentType: "application/json",
data: JSON.stringify(DATA2),
success: function () {
var msg = "update successful";
console.log(msg);
htmlOutput(msg);
},
});
}
function delete_() {
$.ajax({
type: "DELETE",
url: URL + ID,
success: function () {
var msg = "delete successful";
console.log(msg);
htmlOutput(msg);
},
});
}
Also refer Fetch-CRUD