2017-01-03 33 views
2

ajax我有什麼問題嗎? get_details.php不會在模態使用ajax填充來自​​php頁面的數據的bootstrap模態

$('#myModal').on('show.bs.modal', function(){ 
    $.ajax 
    ({ 
     type: "POST", 
     url: "get_details.php", 
     data: dataString, 
     cache: false, 
     success: function(r) 
     { 
      $("#detail").html(r); 
     } 
    }); 
}); 

加載這麼說吧,我這裏面get_details.php。我想使「測試」是在模態

<?php echo "test";?> 

這裏是我的模態

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
     <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
     </div> 
     <div class="modal-body" id="detail"> 

     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     </div> 
    </div> 
    </div> 
</div> 
+1

檢查你怎麼得到的迴應'的console.log(R)' – Thamaraiselvam

+0

另外我想,'類型: POST'是錯誤的,因爲你想'GET'的東西,而不是張貼。 – Twinfriends

+1

@Thamaraiselvam是對的,ajax的回報是什麼? – vijay

回答

0

至於你提到HTTP 404

充分URL 例如http://localhost/yourapp/get_details.php

$('#myModal').on('show.bs.modal', function(){ 
    $.ajax 
    ({ 
     type: "POST", 
     url: "http://localhost/yourapp/get_details.php", 
     data: dataString, 
     cache: false, 
     success: function(r) 
     { 
      $("#detail").html(r); 
     } 
    }); 
}); 
1

不要有評論權限,因此在回答寫作。 檢查Developer Tools(F12)的Network選項卡中的XHR請求狀態,無論它是否調用get_details.php?

而且JFYI,「show.bs.modal」事件將模態的開幕之前進行發射和模態被打開時「shown.bs.modal」必火。

+0

這是調用get_details.php,但狀態是404 @ pravindot17 –

+0

這意味着該文件was'nt在腳本的同一目錄中,因爲你已經提到「url:get_details.php」 – pravindot17

相關問題