开发者

How to update jQuery dialog after ajax response

开发者 https://www.devze.com 2022-12-25 05:31 出处:网络
I would like to update jQuery dialog aft开发者_如何学JAVAer receiving ajax response. Here is my definition

I would like to update jQuery dialog aft开发者_如何学JAVAer receiving ajax response.

Here is my definition

  var $dialog = jQuery('<div>Wait</div>') .html('Sending your message...<img src="../images/AjaxWait.gif" style="float: left; padding-left: 50px;"/>')
.dialog({      
  modal: true,
  width: 160,
  autoOpen: false,
  resizable: false,
  draggable: false,
});

$dialog.siblings(".ui-dialog-titlebar").hide(); 

and before ajax send:

$dialog.dialog('open').dialog('option', 'height', 50);

And once receiving ajax response I am trying following:

jQuery('.ui-dialog-content').dialog('option', 'buttons', 
                            { "Ok": function() { jQuery(this).dialog('close'); } } );

....but nothing happens...... any idea?


I think you cannot modify an existing dialog in this way. To accomplish the task you're faced with just include the button in the first call, but immediately hide it. Once the ajax request has finished just unhide the button. For a proper visual experience just use hide/unhide the whole button pane:

var $dialog = jQuery('<div>Wait</div>') .html('Sending your message...<img src="../images/AjaxWait.gif" style="float: left; padding-left: 50px;"/>')
  .dialog({      
    modal: true,
    width: 160,
    autoOpen: false,
    resizable: false,
    draggable: false,
    buttons: { "Ok": function() { jQuery(this).dialog('close'); }
  })
;

// hide buttons
$dialog.children('.ui-dialog-buttonpane').hide();

In the event handler for ajax complete just do

// unhide buttons
$dialog.children('.ui-dialog-buttonpane').show();

Optionally you may provide an easing identifier to animate the unhiding process.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号