刷新阿贾克斯成功后页面 [英] Reload the page after ajax success

查看:256
本文介绍了刷新阿贾克斯成功后页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题重定向/一个成功的Ajax调用后重装。 这里的情况是:

I have some problems with redirecting/reloading after a successful ajax call. Here is the situation:

我已经删除保存在数组项。当我点击一个按钮,它要求通过AJAX的PHP文件,并取得成功后,我需要重新加载页面。但我有一些问题,这样做。 我在网上搜索,但没有找到工作的解决方案。

I have item for deletion saved in an array. When I click on a button it calls for PHP file via ajax, and after success I need to reload the page. But I have some problem doing this. I searched the internet and couldn't find a working solution.

我有穿过阵列从数据库中删除逐项PHP文件。

I have PHP file which goes through the array deleting item by item from the database.

foreach($arrayVals as $key=>$val)
{
    //bla bla
}

另外,我有jQuery的一部分:

Also, I have jQuery part:

$("#button").live("click",function(){
    $.ajax({
        url, data, type... not important
        success: function(html){
                    location.reload();
                }
    });
});

我的意思是,code ++工程,反而不好。它确实删除项目,但不是所有的人,然后重新加载页面。 就像,如果我有10个项目进行删除,删除它像6-7和3-4项目保持未删除的。

I mean, the code works, but not good. It does delete items, but not all of them and then it reloads the page. Like, if I have 10 items to delete, it deletes like 6-7, and 3-4 items stay undeleted.

它就像它重新加载页面太快,像PHP文件没有足够的时间来处理一切:D

It acts like it reloads the page too soon, like PHP file does not have enough time to process everything :D

推荐答案

BrixenDK是正确的。

BrixenDK is right.

.ajaxStop()回调执行时,所有的Ajax调用完成。这是把你处理一个最好的地方。

.ajaxStop() callback executed when all ajax call completed. This is a best place to put your handler.

$(document).ajaxStop(function(){
    window.location.reload();
});

这篇关于刷新阿贾克斯成功后页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆