简体   繁体   中英

Close JQuery Ui dialog from ajax loaded content

I'm trying to add a close a jquery ui dialog box from an ajax loaded content.

Here is some code :

    <script>
        $(".add_as_friend").click(function(){
            $("#dialog-modal").load("/friends/add_popup/"+$(this).attr('id')).dialog({
                title: sprintf('<?=_("Ajouter %s comme ami");?>',$(this).attr('rel')),
                width: 500,
                height: 350,
                modal: true,
                buttons: {
                    "<?=_("Annuler");?>": function() {
                        $( this ).dialog( "close" );
                    }
                }
            });
        });
    </script>

and the call to close it from the ajax would be something like

$(".add").click(function(){
  //submit a form 
  // close modal box and redirect main window
});

You could try calling the dialog.close() method on the div you turned into a dialog.

$(".add").click(function(){
  $('#dialog-modal').dialog('close');
});

您可以在jQuery UI本身中使用.dialog( "close" )方法。

The modal box is actually in the same window, so you could get by with simply redirecting from the click handler. If you really want to do the close, simply invoke the close method on the dialog.

 $('.add').click( function() {
      $.ajax( $('form').attr('action'), $('form').serialize(), function(data) {
             // optional since we're unloading the page
            $('#dialog-modal').dialog('close');
            location.href = data.RedirectUrl;
      });
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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