Javascript jQuery事件关闭太快

Javascript jQuery事件关闭太快,javascript,jquery,ajax,web,Javascript,Jquery,Ajax,Web,以下是我的jQuery代码: $("#remove").click(function(e) { $.confirm({ 'title': 'Delete Confirmation', 'message': 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?', 'buttons': {

以下是我的jQuery代码:

$("#remove").click(function(e) {
    $.confirm({
        'title': 'Delete Confirmation',
        'message': 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?',
        'buttons': {
            'Yes': {
                'class': 'blue',
                'action': function() {
                    $.ajax({
                        'url': "../api/removeHost.php?id=" + $("#id").val(),
                        'success': function(d) {
                            var json = JSON.parse(d);
                            //Display error text
                            if (json[0] == 0) {
                                createMessageDialog("General Error", json[1][1]);
                                //If all is successful reload the listServersBody to reflect the new changes and create the success popup
                            } else {
                                $("#listBody").load(lastPopulateAPICall); //Refresh the search\browse list with the new edits/
                                enableAdd();
                                createMessageDialog("Success", "Successfully removed!");
                            }
                        }
                    });
                }
            },
            'No': {
                'class': 'gray',
                'action': function() {} // Nothing to do in this case. You can as well omit the action property.
            }
        }
    });
});....

function createMessageDialog(title, message) {
    $.confirm({
        'title': title,
        'message': message,
        'buttons': {
            'Ok': {
                'class': 'blue',
                'action': function() {
                    alert('dd');
                }
            },
            'No': {
                'class': 'gray',
                'action': function() {} // Nothing to do in this case. You can as well omit the action property.
            }
        }
    });
}
$(“#删除”)。单击(函数(e){
美元。确认({
'标题':'删除确认',
“消息”:“您将要删除此项目。
以后无法还原它!是否继续?”, “按钮”:{ “是的”:{ “类”:“蓝色”, “操作”:函数(){ $.ajax({ 'url':“./api/removeHost.php?id=“+$(“#id”).val(), “成功”:函数(d){ var json=json.parse(d); //显示错误文本 如果(json[0]==0){ createMessageDialog(“一般错误”,json[1][1]); //如果全部成功,请重新加载listServersBody以反映新的更改并创建成功弹出窗口 }否则{ $(“#listBody”).load(LastPopulatePicall);//使用新编辑刷新搜索\浏览列表/ enableAdd(); createMessageDialog(“成功”,“成功删除!”); } } }); } }, “否”:{ “类”:“灰色”, “action”:函数(){}//在这种情况下无需执行任何操作。您也可以省略action属性。 } } }); });.... 函数createMessageDialog(标题、消息){ 美元。确认({ “标题”:标题, “消息”:消息, “按钮”:{ “好的”:{ “类”:“蓝色”, “操作”:函数(){ 警报(“dd”); } }, “否”:{ “类”:“灰色”, “action”:函数(){}//在这种情况下无需执行任何操作。您也可以省略action属性。 } } }); }

调用createMessageDialog()函数是因为触发了我删除的调试警报。就好像在第一个盒子关闭之前,盒子没有足够的时间来显示。我甚至将第一个确认对话框复制到createMessageDialog函数中,但没有成功。我正在使用下面的确认插件

可能您单击的默认操作是刷新页面

$("#remove").click(function(e) {
    e.preventDefault(); // cancel the click
    ...

没用。我不是在重新翻页。我认为这是因为第一个确认正在淡出,并在下一个确认加载之前完成,所以您是说第一个确认会出现,问题是当您单击“是”按钮时?会调用“是”createMessageDialog(),但该框不会出现。我需要一个类似于$.ajax的成功属性的功能。完成所有操作后,它将运行一个函数调用它并回调load()?