代码之家  ›  专栏  ›  技术社区  ›  bdl

关于AjaxStart事件的jQuery模式对话框

  •  4
  • bdl  · 技术社区  · 16 年前

    我试图通过AjaxStart、AjaxStop/AjaxComplete事件使用jQueryUI模式对话框作为加载指示器。当页面触发时,一个Ajax处理程序加载一些数据,模式对话框显示得很好。但是,当Ajax事件完成时,它从不隐藏或关闭对话框。从本地服务器返回的代码非常小,因此实际的Ajax事件非常快。

    这是我的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(); });
    

    Ajax事件只是一个普通的事件 $.ajax({}) 获取方法调用。

    基于这里和谷歌的一些搜索,我尝试修改Ajaxstop处理程序以使用 $("#modalwindow").close() , $("#modalwindow").destroy() 等(此处所指的“ModalWindow”是为了提供明确的上下文)。

    我也试过用这个标准 $("#modalwindow").dialog({}).ajaxStart(... 也。

    我应该将事件绑定到其他对象吗?或者从内部呼叫他们 $.ajax() 完全事件?

    我应该提到,我正在测试最新的IE8、FF 3.6和Chrome。都有相同/相似的效果。

    2 回复  |  直到 16 年前
        1
  •  6
  •   bdl    16 年前

    找到答案:

      $("#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 .

    当然,在这一切中,我现在意识到它打开和关闭的速度太快,以致于事无补。哦,好吧,希望有人会觉得这有帮助。

        2
  •  1
  •   kevingessner    16 年前

    "Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests." 是否同时运行其他Ajax请求?你会想用的 ajaxComplete 或回调选项 .ajax() 相反,只需完成一个。