//This for view.....
{ "mData": "View",
render:function(data ,type,row){
return '<a href="${pageContext.request.contextPath}/view?emp_Id='+row.emp_Id+'&isView=true">View</a>';
},
/* className: "dt-body-center",
orderable: false */
},
//This is for delete
{ "mData": "Delete",
render:function(data ,type,row){
/* return '<button><a id="btn" href="${pageContext.request.contextPath}/delete?emp_Id='+row.emp_Id+'">Delete</a></button>'; */
return '<button id="delete_Id" >Delete</button>';
},
className: "dt-body-center",
orderable: false
},
这里我想要做的是当我点击按钮我想要一个确认框,如果我按下确定必须删除数据。我已经完成了使用ajax。下面是我的源代码,我有我已经给了编辑的直接链接,所以它正在工作。但同时我想为那个点击事件...我可以有一个解决方案吗?
//jquery
$("#delete_Id").on("click",function () {
var val = $(this).attr('row.emp_Id');
console.log("val:"+val);
var myUrl = '${pageContext.request.contextPath}/delete?emp_Id='+val+' ';
if (confirm('Are you sure you want to delete this?')) {
$.ajax({
url: 'myUrl',
type: "POST",
data:{"emp_Id":'row.emp_Id'},
success: function (text) {
response = text;
}
});
getAjaxResponce();
}
});
答案 0 :(得分:0)
请删除更新代码
$("#delete_Id").on("click",function () {
var val = $(this).attr('row.emp_Id');
console.log("val:"+val);
var myUrl = '${pageContext.request.contextPath}/delete?emp_Id='+val+' ';
if (confirm('Are you sure you want to delete this?')) {
$.ajax({
url: myUrl,
type: "POST",
data:{"emp_Id":'row.emp_Id'},
success: function (text) {
response = text;
}
});
getAjaxResponce();
}
});
答案 1 :(得分:0)
您必须在呈现按钮后声明点击事件。否则它不会工作。如果你不能,你必须采取这样的不同解决方案:
<button id="delete_Id" onclick="delete()">Delete</button>
function delete () {
var val = $(this).attr('row.emp_Id');
console.log("val:"+val);
var myUrl = '${pageContext.request.contextPath}/delete?emp_Id='+val+' ';
if (confirm('Are you sure you want to delete this?')) {
$.ajax({
url: myUrl,
type: "POST",
data:{"emp_Id":'row.emp_Id'},
success: function (text) {
response = text;
}
});
getAjaxResponce();
}
});