jQuery事件关闭得太快了

时间:2012-07-19 13:38:17

标签: 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': {
            '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.
            }
        }
    });
}

正在调用createMessageDialog()函数,因为我删除了我删除的调试警报。就好像盒子在第一个关闭之前没有足够的时间显示或者某些东西。我甚至将第一个确认对话框复制到createMessageDialog函数中无济于事。我使用以下确认插件http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/

1 个答案:

答案 0 :(得分:0)

您点击的内容的默认操作可能是刷新页面。

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