最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Refresh parent page when jQuery UI Dialog is closed - Stack Overflow

programmeradmin5浏览0评论

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?

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?

Share Improve this question asked Sep 28, 2015 at 15:03 George BacaGeorge Baca 1791 gold badge3 silver badges14 bronze badges 1
  • Is the dialogue a promise? you could use that and wait for a result before calling a refresh function... What @Bernhard said. – Jon Wells Commented Sep 28, 2015 at 15:06
Add a ment  | 

3 Answers 3

Reset to default 13

Use the dialogclose event (http://api.jqueryui./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();
     }
  });

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();
     }
});

When you initialize the dialog, add the close listener.

$( ".selector" ).dialog({
  close: function( event, ui ) { window.location.reload(true); }
});
发布评论

评论列表(0)

  1. 暂无评论