[英]How to return true or false values using JavaScript or jQuery after click on confirm or cancel button from confirm box?
[英]jquery how remove popover parents on click confirm button?
我正在嘗試發送 ajax 請求並在成功后刪除彈出框的父級請求成功但我無法訪問彈出框的父級以將其刪除,這是問題的根源
// delete work form portfolio $(document).on("click", "#delete-work", function(){ var id_val= $(this).attr("data-id"); $.ajax({ url: "ajax/portfoliojx.php", type: "POST", data: { name: "delete_work", id: id_val, }, dataType: "JSON" }).done(function(data){ // check if responed email error $(this).parents(".work").remove(); }); })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="work"> <div class="col-md-3"> <div class="thumbnail"> <a href=""> <img src="uploads/portfolio/251442-7.jpg" title="hello" alt="hello"> </a> <div class="caption"> <a href=""><h4 class="tite">hello</h4></a> </div> <hr> <a href="?do=edit&id=23" class="btn btn-default">edit <i class="fa fa-edit"></i></a> <a tabindex="0" class="btn btn-danger pull-left" role="button" data-toggle="popover" data-trigger="focus" data-placement="top" title="" data-content="<button class='btn btn-defualt'>no</button><span class='pull-left'><button id= 'delete-work' data-id= '23' class='btn btn-danger'>yah</button></span>" data-original-title="are you sure from this?"> delete <i class="fa fa-trash"></i></a> </div> </div> </div>
在 Ajax 回調中 scope 應該是 Ajax 所以這不會起作用。 以下代碼適用於您的情況
$(document).on("click", "#delete-work", function(){
var _self = this;
var id_val= $(this).attr("data-id");
$.ajax({
url: "ajax/portfoliojx.php",
type: "POST",
data: {
name : "delete_work",
id : id_val,
},
dataType: "JSON"
}).done(function(data){
// check if responed email error
$(_self).parents(".work").remove();
});
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.