2013-02-27 119 views
1

1.我是一個頁面,點擊按鈕可以調出模態。我想要做的是將所有模型移至單獨的頁面。我試過Bootstrap - 載入模態位於其他頁面和表單提交模態

$('#newSection').click(function(){ 
     $('#temp').load('adminmodels.php'); 
     $('#newSectionModal').modal('show'); 
    }); 

第一次點擊時,沒有任何反應。在隨後的點擊中,模式會自動出現並淡化。請建議並修改我的代碼。

2.我想從模態中提交一個表單,然後在模態本身顯示響應。

$(document).ready(function(){ 
     $('#user_button').click(function(e){ 
      e.preventDefault(); 
      $(this).attr('disabled',true); 
      $.post('__admin_ajax.php',postString,function(response){ 
       $('#user-modal-body').html(response); 
      }); 
     }); 
    }); 

以前的表單提交對後續模態加載保留的響應。

回答

0

我發現這種類型的邏輯,使用iframe更容易。

<div id="newSectionModal"> 
    <iframe id="modal_frame"/> 
<div> 

然後在代碼中。

$('#newSection').click(function(){ 
    $('#modal_frame').attr('src', 'adminmodels.php'); 
    $('#newSectionModal').modal('show'); 
}); 

因爲它在一個框架中,您可以像處理它自己的窗口一樣處理表單提交。在任何時候,你都可以通過調用window.parent觸發父框架。例如:window.parent.trigger(「form-submitted」)