イム初心者ので、私は、私はインターネット上で、ブートストラップモーダルでAjaxの読み込みPHPファイルに関するいくつかのチュートリアルを見つけるいくつかのlitle助け:) が必要ですが、まだいくつかの問題を抱えている。..ジャバスクリプトではJavaScript初心者、ロードPHPファイル
ここですコード:
のpublic_html /資産/のJS/m.js
$(document).ready(function(){
// modals
$(document).on('click', '#getUser', function(e){
e.preventDefault();
var uid = $(this).data('id'); // it will get id of clicked row
$('#dynamic-content').html(''); // leave it blank before ajax call
$('#modal-loader').show(); // load ajax loader
$.ajax({
url: 'ajax.php',
type: 'POST',
data: 'id='+uid,
dataType: 'html'
})
.done(function(data){
console.log(data);
$('#dynamic-content').html('');
$('#dynamic-content').html(data); // load response
$('#modal-loader').hide(); // hide ajax loader
})
.fail(function(){
$('#dynamic-content').html('<i class="glyphicon glyphicon-info-sign"></i> Something went wrong, Please try again...');
$('#modal-loader').hide();
});
});
});
公開/資産/含める/ pagefile.php
呼び出すモーダル:
<button data-toggle="modal" data-target="#view-modal" data-id="$cat[id]" id="getUser" class="btn btn-success">Open</button>
<div id="view-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">
<i class="glyphicon glyphicon-user"></i> User Profile
</h4>
</div>
<div class="modal-body">
<div id="modal-loader" style="display: none; text-align: center;">
<img src="ajax-loader.gif">
</div>
<!-- content will be load here -->
<div id="dynamic-content"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
のpublic_html/ajax.php
<?php
include("connect_db.php");
if (isset($_REQUEST['id'])) {
$id = $_REQUEST['id'];
echo "$id";
} else {}
?>
すべてがよさそうだが、私は 何かが入った示し、AJAXコンテンツをロードし、常にモーダルカント間違っています。もう一度お試しください...
そして、私はajax.phpファイルにパス/タスクを追加したいのですが、それをjavascriptに追加する方法と、投稿する/ varを増やす方法を尋ねますか?
おかげでたくさん、私の悪い英語のため申し訳ありません:D
あなたはAJAXリクエストajax.php
の相対URLを使用している