在ajaxStart事件jQuery的模态对话框 [英] jQuery modal dialog on ajaxStart event

查看:117
本文介绍了在ajaxStart事件jQuery的模态对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个jQuery UI的模态对话框,经由ajaxStart,ajaxStop / ajaxComplete事件负载指示。当页面大火,一个Ajax处理程序加载一些数据,和模态对话框显示就好了。但是,它从来没有隐藏或关闭对话框时,阿贾克斯事件完成。它是code从返回的本地服务器一个非常小的一点,所以实际的Ajax事件是非常快的。

I'm trying to use a jQuery UI modal dialog as a loading indicator via the ajaxStart, ajaxStop / ajaxComplete events. When the page fires, an Ajax handler loads some data, and the modal dialog shows just fine. However, it never hides or closes the dialog when the Ajax event is complete. It's a very small bit of code from the local server that is returned, so the actual Ajax event is very quick.

下面是我的实际code的模式DIV:

Here's my actual code for the modal div:

      $("#modalwindow").dialog({
              modal: true,
              height: 50,
              width: 200,
              zIndex: 999,
              resizable: false,
              title: "Please wait..."
      })
      .bind("ajaxStart", function(){ $(this).show(); })
      .bind("ajaxStop", function(){ $(this).hide(); });

阿贾克斯事件仅仅是一个普通的 $。阿贾克斯({}) GET方法调用。

The Ajax event is just a plain vanilla $.ajax({}) GET method call.

根据某些搜索在这里和谷歌,我试着改变ajaxStop处理程序使用 $(#modalwindow)。关闭() $(#modalwindow)。销毁()等。(#modalwindow这里称为给予明确的情况下)。

Based on some searching here and Google, I've tried altering the ajaxStop handler to use $("#modalwindow").close(), $("#modalwindow").destroy(), etc. (#modalwindow referred to here as to give explicit context).

我也试着使用标准的 $(#modalwindow)。对话框({})。ajaxStart(...

我应该将事件绑定到不同的对象呢?还是从 $。阿贾克斯()完成事件中调用他们?

Should I be binding the events to a different object? Or calling them from within the $.ajax() complete event?

我要指出,我测试了最新的IE8,FF 3.6和Chrome。所有具有相同/相似的效果。

I should mention, I'm testing on the latest IE8, FF 3.6 and Chrome. All have the same / similar effect.

推荐答案

找到了答案:

  $("#modalwindow").dialog({
          modal: true,
          height: 50,
          width: 200,
          zIndex: 999,
          resizable: false,
          title: "Please wait..."
  })
  .bind("ajaxStart", function(){
      $(this).dialog("open"); })
  .bind("ajaxStop", function(){
      $(this).dialog("close");
  });

请注意自我: RTFM

当然,在这一切,现在我认识到,它打开和关闭,以便快速地是无用的。哦,好吧,希望有人会发现这是很有帮助的。

Of course in all this, now I realize that it opens and closes so quickly as to be useless. Oh well, hopefully someone will find this helpful.

这篇关于在ajaxStart事件jQuery的模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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