3

So every time a specific dialog box in jQuery UI is closed I want the parent page to be refreshed. How can I achieve this.

jQuery Code:

        $(document).ready(function() { 
         var dlg=$('#createTeam').dialog({
         title: 'Create a Team',
         resizable: true,
         autoOpen:false,
         modal: true,
         hide: 'fade',
         width:600,
         height:285
      });


      $('#createTeamLink').click(function(e) {
          dlg.load('admin/addTeam.php');
          e.preventDefault();
          dlg.dialog('open');
      }); 
}); 

HTML Code:

<button href="" type="button" id="createTeamLink" class="btn btn-primary custom">Create Team</button>
<div id="createTeam" class="divider"></div>

How do I get the main parent page to refresh/reload after the dialog box is closed?

George Baca
  • 179
  • 1
  • 3
  • 14
  • Is the dialogue a promise? you could use that and wait for a result before calling a refresh function... What @Bernhard said. – Jon Wells Sep 28 '15 at 15:06

3 Answers3

13

Use the dialogclose event (http://api.jqueryui.com/dialog/#event-close).

var dlg=$('#createTeam').dialog({
     title: 'Create a Team',
     resizable: true,
     autoOpen:false,
     modal: true,
     hide: 'fade',
     width:600,
     height:285,
     close: function(event, ui) {
          location.reload();
     }
  });
Bernhard
  • 8,583
  • 4
  • 41
  • 42
1

You should be able to do this with the reload() function:

window.location.reload();

In your code:

var dlg=$('#createTeam').dialog({
     title: 'Create a Team',
     resizable: true,
     autoOpen:false,
     modal: true,
     hide: 'fade',
     width:600,
     height:285,
     close: function() {
         window.location.reload();
     }
});
CDelaney
  • 1,238
  • 4
  • 19
  • 36
0

When you initialize the dialog, add the close listener.

$( ".selector" ).dialog({
  close: function( event, ui ) { window.location.reload(true); }
});
epascarello
  • 204,599
  • 20
  • 195
  • 236