<script>
$(function(){
load();
$(".col-xs-12").on("click",".close",function(){
var id = $(this).attr("data-id");
$.ajax({
url:"http://localhost:5100/tag",
type:"DELETE",
data:{_id: id},
success:function(res){
if(res.status === 200){
console.log("删除成功");
}
}
})
})
function load() {
$.ajax({
url:"http://localhost:5100/tag",
type:"GET",
success:function(res){
if(res.status===200){
const data = res.data;
let html = "";
for (let index = 0; index < data.length; index++) {
const element = data[index];
html += `<div class="alert alert-info pull-left">
<button type="button" data-id="${element._id}" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>${element.text}</strong>
</div>`;
}
$(".col-xs-12").html(html);
}
console.log(res);
},
error:function(err){
console.log(err);
}
})
}
})
</script>