的fancybox不关闭Ajax调用后, [英] Fancybox not closing after ajax call

查看:230
本文介绍了的fancybox不关闭Ajax调用后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法关闭我的想象中在某些情况下,Ajax调用后。

I'm having trouble closing my fancy box in some cases after an ajax call.

 $(document).ajaxStop(function() {
    function(){$.fancybox.close()};
 });

 $(document).ajaxStart(function() {
    $("a#load_gif").trigger('click');
 });

下面是我的code处理花哨的盒子。所以我的问题是,如果Ajax调用是非常简单和快速的框没有关闭,但如果调用时间越长,会自动关闭,因为它应该。

Here's my code handling the fancy box. So my problem is that if the ajax call is very brief and fast the box doesn't close, however if the call is longer it closes automatically as it should.

我已经找到了修复其随之而来的这一行

I have found a fix which goes along the line of this

$(document).ajaxStop(function() {
    setTimeout(function(){$.fancybox.close()},500);
});

但说实话这种解决方案并不好看。我能做些什么,使花式盒接近即使AJAX调用返回速度非常快?根据它获取的行数的Ajax调用的长度是可变的。

But honestly that solution is not good looking. What can I do to make the fancy box close even if the ajax call is returned very fast? The length of the ajax call is variable depending on the number of rows it has to fetch.

任何帮助和/或建议,AP preciated。

Any help and/or suggestions are appreciated.

推荐答案

这似乎是你有一个竞争条件,也许是的fancybox还没有完成被创建,它的定义贴心的功能还没有当你的Ajax调用试图将火关闭该关闭的功能。

It seems like you have a race condition and maybe the fancybox isn't finished being created and doesn't have it's close function defined yet when your AJAX call is attempting to fire off that close function.

我推荐一个2步骤的过程,触发的fancybox关闭。创建2个全局变量 ajaxStop = FALSE; fancyboxDone = FALSE;

I recommend a 2 step process that triggers the fancybox to close. Create 2 global variables ajaxStop = false; and fancyboxDone = false;

创建这样一个功能:

function closeFancyBox(){
    if(ajaxStop && fancyboxDone){
        $.fancybox.close();
        ajaxStop = fancyboxDone = false;
    }
}

然后改变你的AJAX停止:

Then change your ajax stop to :

 $(document).ajaxStop(function() {
    function(){
      ajaxStop = true;
      closeFancyBox()
    };
 });

最后添加的onComplete功能,你的fancybox,做同样的作为Ajax停止,但集 fancyboxDone = TRUE 而不是 ajaxStop

所以,现在无论是哪一个完成第一和第二,他们将能够检查对方的身份和火的密切恰如其分。

So now no matter which one finishes first and second they will be able to check on each other's status and fire the close appropriately.

这篇关于的fancybox不关闭Ajax调用后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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