简体   繁体   English

jQuery UI动画对话框显示/隐藏问题

[英]jQuery UI Animated Dialog Showing/Hiding Problem

I am using a dialog as a loading overlay for various AJAX functions, but when the dialog has show or hide animations attached to it, the dialog will not open/close until the AJAX function is complete. 我将对话框用作各种AJAX功能的加载叠加层,但是当对话框具有显示或隐藏的动画时,在AJAX功能完成之前,对话框不会打开/关闭。

Here is the (simplified) code I am using: 这是我正在使用的(简化)代码:

$("#loading_dialog").dialog(
{
  show: "fade",
  hide: "fade",
  closeOnEscape: false,
  stack: false,
  draggable: false,
  height: 421,
  width: 500,
  modal: false,
  position: {my: 'right', at: 'left', of: '#side_div', offset: "2 0"},
  resizable: false,
  dialogClass: 'loading',
  zIndex: 900,
  autoFocus: false
});

$("#start_ajax").click(function()
{
  $("#loading_dialog").dialog("open");

  $.when(ajaxFunction())
  .then(function()
  {
    //do stuff
    $("#loading_dialog").dialog("close");
  })
  .fail(function()
  {
    //handle error
  });
});

#loading_dialog doesn't open until the call in ajaxFunction() has finished, but does immediately when I comment out the show option in the dialog initialization. #loading_dialog没有打开,直到呼叫ajaxFunction()已经完成,但是当我注释掉在对话框初始化显示选项将立即。 The same happens when I try and close dialogs as well. 当我尝试关闭对话框时也会发生同样的情况。

Is it just me? 只有我吗?

$.when(ajaxFunction())

is your problem. 是你的问题。 Don't wait for the ajax to finish, utilize the ajax callback function. 不要等待ajax完成,请利用ajax回调函数。 The whole idea of AJAX is not blocking, which you are explicitly doing. AJAX的整个想法不是阻塞,而您正在明确地这样做。

Stick this: 坚持:

$("#loading_dialog").dialog("close");

into the ajax callback. 进入ajax回调。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM