从ajax加载的内容关闭JQuery Ui对话框

时间:2010-12-10 11:40:47

标签: jquery jquery-ui

我正在尝试从ajax加载的内容中添加一个关闭jquery ui对话框。

以下是一些代码:

    <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>

并且从ajax关闭它的调用就像是

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

3 个答案:

答案 0 :(得分:4)

您可以尝试在转换为对话框的div上调用dialog.close()方法。

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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

模态框实际上位于同一个窗口中,因此只需从单击处理程序重定向即可。如果你真的想要关闭,只需在对话框中调用close方法。

 $('.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;
      });
 });
相关问题