刷新确认

时间:2013-12-11 21:40:21

标签: javascript jquery

请在发布成功后帮助我刷新页面,而不是动画。我已经尝试过window.opener.location.href,但它没有任何好处。谢谢你的帮助!

$(function () {
    $(".delbutton").click(function () {
        //Save the link in a variable called element
        var element = $(this);
        //Find the id of the link that was clicked
        var del_id = element.attr("id");
        //Built a url to send
        var info = 'id=' + del_id;
        if (confirm("Are you sure you want to remove this item?")) {
            $.ajax({
                type: "GET",
                url: "delete",
                data: info,
                success: function () {

                }
            });
            $(this).parents(".record").animate({
                backgroundColor: "#fbc7c7"
            }, "fast")
                .animate({
                opacity: "hide"
            }, "slow"); //instead of this, I want page to refresh after confirmation
        }
        return false;
    });
});

3 个答案:

答案 0 :(得分:0)

为什么不在成功时删除与id对应的元素?

编辑在删除元素时添加动画:

  $(function () {
    $(".delbutton").click(function () {
        //Save the link in a variable called element
        var element = $(this);
        //Find the id of the link that was clicked
        var del_id = element.attr("id");
        //Built a url to send
        var info = 'id=' + del_id;
        if (confirm("Are you sure you want to remove this item?")) {
            $.ajax({
                type: "GET",
                url: "delete",
                data: info,
                success: function () {
                   // ADDITION HERE
                $('div[id='+ del_id +']').hide('slow', function(){ $('div[id='+ del_id +']').remove(); });

                }
            });

        }
        return false;
    });
});

答案 1 :(得分:0)

我不确定为什么你在AJAX调用后刷新页面,但是如果你真的需要,那就是如何做到这一点。当用户确认删除时,发送AJAX请求,如果成功,则刷新页面。

if (confirm("Are you sure you want to remove this item?")) {
    $.ajax({
        type: "GET",
        url: "delete",
        data: info,
        success: function () {
            window.location.reload();
        }
    });
}

答案 2 :(得分:0)

事实证明,任何第三方插件都不是问题,但我需要包含<tr class="record">。它之后就可以了!