刪除要刷新才能顯示
$(function() {
? $(".del").click(function(e) {
? ? var target = $(e.target); //get the object clicked
? ? var id = target.data("id");
? ? var tr = $("item-id-" + id);
? ? $.ajax({
? ? ? type: "DELETE",
? ? ? url: "/admin/list?id=" + id
? ? }).done(function(results) {
? ? ? if (result.success == 1) {
? ? ? ? if (tr.length > 0) {
? ? ? ? ? tr.remove();
? ? ? ? }
? ? ? ? window.location.reload();
? ? ? }
? ? });
? });
});
js代碼
app.delete("/admin/list", function(req, res) {
? var id = req.query.id; //to get the value after '?' of the request url
? if (id) {
? ? movie.deleteOne({ _id: id }, function(err, movie) {
? ? ? if (err) {
? ? ? ? console.log(err);
? ? ? } else res.json({ success: 1 });
? ? });
? }
});
server端代碼