重定向并不总是使用JQuery UI对话框

时间:2014-07-03 01:05:47

标签: javascript php jquery jquery-ui redirect

我遇到一些问题,总是让jquery ui对话框重定向。当我点击删除链接时,它会询问您是否确定。如果单击“删除”按钮,则应将其重定向。问题是它并不总是第一次重定向。它通常仅在您单击第二次删除对话框窗口后才起作用。有谁知道为什么会这样?我已尝试在多个位置使用重定向,包括在查询发生后以及删除查询关闭之前和之后。

对话框重定向的页面(在底部);

<a href="#" class="delete">Delete</a>

<script>
    var id = "";
    //run function after jquery dialong confirm
    //step 1 - the action
    $(".delete").click(function(e) {
        e.preventDefault();
        id = $(this).parent().attr('id');
        //console.log(id); // check you get it first
        $('#dialog').dialog('open');
    });
    //step 2 - the dialog modal
    $("#dialog").dialog({
        resizable: true,
        height: 100,
        modal: true,
        autoOpen: false,
        buttons: {
            "Delete": function() {
                //console.log(id + " made it to dialog"); // make sure our id makes it this far
                deleteUser(id); // run delete photo function
                window.location.href = "http://www.speechvive.com/adminSLP.php";
                $(this).dialog("close");

            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });
    //step 3 - php function
    function deleteUser(user_id) {
        //console.log(user_id + " made it to function"); // make sure our id makes it this far
        $.ajax({
            type: "POST",
            url: "/adminSLP.php#delete",
            data: {user_id: user_id}
        }).done(function(msg) {
            console.log(msg);
            //no message bc we did a fadeOut
            //var msg would show any errors from our php file
        });
    }
    ;
</script>

0 个答案:

没有答案