2016-08-04 13 views
0

我想在我的主頁上調用一個按鈕從另一個頁面調用模式。加載ajax頁面中的引導模態,並自動啓動該模式,所有一次

我需要這個模式在加載後自動啓動。

我沒有找到任何關於它的信息。 (還是我錯過嗎?!)

我的代碼:

我打電話這個js功能:

<script> 
function startb(plc) 
{ 
    $.ajax({ 
      url: "gb.php?plc="+plc 
      }).done(function(data) { 
      $("#large-div").html(data); 
      }); 

    //the id of the modal in the gb.php code is: "inside-modal" 
     $('#inside-modal').modal('show'); 

} 
</script> 

<body> 

<div id="large-div" name="large-div"> 

</div> 

<button onclick="startb('28')">start plc</button> 



</body> 
+0

向我們展示您嘗試過的方式,我很樂意幫助您瞭解您錯過的內容。 – technophobia

+0

ajax您想要加載的頁面,然後在ajax完成時填充模式。這很容易。 – noob

+0

我插入了代碼。感謝名單! – user3495363

回答

2

你需要把$()模式()函數調用Ajax請求

AJAX的回調函數,顧名思義內是異步的,所以

.modal()
調用發生之前的股利實際上與您的新的HTML內容填充。

解決方案:

$.ajax({ 
     url: "gb.php?plc="+plc 
     }).done(function(data) { 
     $("#large-div").html(data); 
     $('#inside-modal').modal('show'); 
     }); 

希望它可以幫助

編輯:

@季米特里斯Nastos,沒看到你的評論 - 完全一樣,這個答案。將upvote評論。

+0

Thanx!有效。 之前 - 我試圖從不同的地方,如ajax調用之外或從不同的功能調用模態。我甚至都不認爲從ajax調用中調用它是可能的,因爲即使完成了ajax調用,js代碼也沒有創建(我檢查了一個警報,看它何時完成添加頁面) - s \ this讓我吃驚 - 但它工作 - thanx! upvoted! – user3495363