0

我正在使用 jquery ajax 从一行表结果中删除一条记录。所有这一切都在工作......然而,我决定将引导箱确认对话框添加到组合中。

问题是弹出对话框,当我单击确认时,ajax 位完成并从表中删除记录,但是引导框对话框再次弹出(它这样做 3 次)直到它重定向到http ://mydomain.com/undefined

我的基于引导程序的 HTML 看起来像这样

<button class="btn btn-xs btn-danger ajax-delete"
                            data-record-id="1"
                            data-which-table="commissions"
                            data-ajax-url="http://domain.com/delete.php">
<i class="icon-remove">
</i>
</button>

和这样的js

$(document).on("click", ".ajax-delete", function(e){

//get variables from link attributes
var id = $(this).attr("data-record-id");
var dbtable = $(this).attr("data-which-table");
var ajaxurl = $(this).attr("data-ajax-url");
var parent = $(this).parents("tr:first"); //delete the whole row <tr></tr>

e.preventDefault();

//process bootboxjs confirm alert box   
bootbox.confirm("Are you so sure?", function(result){
    //if agreed, start ajax 
    if (result) {   


        //______Ajax Bit________________________
        $.ajax({
            type: 'post',
            url: ajaxurl,
            data: 'id=' + id + '&dbtable=' + dbtable,

            //success, annimate and remove row
            success: function(){
                parent.slideUp(300, function(){
                    parent.remove();
                });
            }

            //todo fail output
        });
    }                 

});
});
4

0 回答 0