私は動的に入力されたテーブルを持つページ(products.php)を持っています。各行にはモーダルを開くボタンがありますが、パラメータをモーダルに渡すには、まず、現在のページ(products.php)でモーダルを宣言しました。次に、別のページ(modal.php)からajaxを使って残りのモーダルを呼び出します。私はajaxを使用する前に、ドロップダウン内のすべてのオプションをpopuplatedしましたが、私はこのモーダルを表示することで同じことをすることはできません。私はPHPのhrefを使用することができますが、私は私のモーダルのデータベースに提出に使用する私のjqueryのスクリプトがもう働かないため、それはなぜ私はajaxでこれをやって考えている。私はこれがうまくajaxで動作していない理由を知りたいです。ajaxを使用してparamsをモーダルに渡そうとしていますか?
HERESにサンプルコード:あなたは次のように彼らは2つの行を修正する必要があり
products.php
<html>
<header>
<script>
function modalValues(val1,val2){
if(window.XMLHttpRequest){
xhttp = new XMLHttpRequest();
}else{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function(){
if(xhttp.readyState == 4 && xhttp.status == 200){
document.getElementById("load_here").innerHTML = xhttp.responseText;
}
};
xhhtp.open("POST","modal.php?id3="+val1+"&id="+val2,true);
xhttp.send();
}
</script>
</header>
<body>
<div class="modal fade" data-keyboard="false" id="product_customerModal" tabindex="-1" role="dialog" aria-labelledby="product_customerModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div id="load_here" class="modal-content">
</div>
</div>
</div>
<table>
<?php
global $link;
$query = "blah,blah";
$result_set = mysqli_query($link,$query);
$number = mysqli_num_rows($result_set);
for($count=0;$count<$number;$count++){
$result = mysqli_fetch_array($result_set);
echo "<tr>";
echo "<td>{$result['field1']}</td>";
echo "<td>{$result['field2']}</td>";
echo "<td><button onclick='modalValues(<?php echo $result['field1'];?>,<?php echo $result['field2'];?>) data-toggle="modal" data-target='#product_customerModal'></button></td>";
}
?>
</table>
</body>
</html>
そして
modal.php
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" > Date: (<?php echo $date;?>)</h4></div
<div class="modal-body">
<?php
//some php code
?>
<div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
ありがとう、これは私のために働いてくれた –