2015-08-15 64 views
-1

我在這裏有一個示例項目,它將使用ajax獲取屬性的id值,然後使用ajax顯示模式。使用ajax打開模式不起作用

我得到的程序在獲取id方面運行良好,但我的問題是模式沒有顯示。

我測試過的問題是我刪除了模態中的class="modal hide",所以模態出現在表格的下方,而不是在整個頁面的前面。

它只是看起來像表下的另一個部門。

所以現在我的問題是,模式不會彈出。單擊時,如果模態的屬性class="modal hide"沒有任何反應,但是如果沒有像它那樣的屬性,它就會有工作模式,但它不會彈出。

它就像表格下的另一個分部。

我的代碼有什麼問題?

<a type="button" data-toggle="modal" id="11" class="push">Read more</a> 
<script> 
$(document).ready(function() { 
    $('.push').click(function() { 
     var res_id = $(this).attr('id'); 
     $.ajax({ 
      type: 'POST', 
      url: '../php-files/resolve.php', // in here you should put your query 
      data: 'post_id=' + res_id, // here you pass your id via ajax . 
      // in php you should use $_POST['post_id'] to get this value 
      success: function (r) { 
       // now you can show output in your modal 
       $('#mymodal').modal('show'); // put your modal id 
       $('.modal-body').show().html(r); 
      } 
     }); 
    }); 
}); 
</script> 
<!-- Modal --> 
<div id="myModal" class="modal hide fade in" role="dialog"> 
    <div class="modal-dialog"> 
    <!-- Modal content--> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
     <h4 class="modal-title">Modal Header</h4> 
     </div> 
     <div class="modal-body"> 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     </div> 
    </div> 

    </div> 
</div> 
+1

你可以設置一個最小的例子來證明你的問題?你可以用它創建一個小提琴,在JSFiddle上有關於如何製作虛擬AJAX請求的說明。 – Terry

+0

你確定你的請求是成功的嗎?它可能不是,這就是爲什麼這些指令永遠不會執行! – Gacci

+0

在你的按鈕上使用data-target =「#mymodal」 –

回答

0

在成功函數中添加以下代碼

$('#id1').modal('show'); // you 
    $('#body').html(r); 

你的模型應該如下

<div class="modal" id="id1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    ... 
    <div id="body" class="modal-body text-center"> 
     <!-- loading modal.. --> 
    </div> 
    .. 
    </div> 
+0

謝謝,但模態仍然不顯示,但它的內容顯示除了模態。內容只是像導航文本一樣顯示在導航頂部。 – user3802633

+0

謝謝。我已經做到了..我所缺少的只是數據目標!謝謝! – user3802633

+0

你的問題解決了嗎? – Vishu238