Php 尝试使用ajax将参数传递到模式?

Php 尝试使用ajax将参数传递到模式?,php,ajax,Php,Ajax,我有一个页面(products.php),其中有一个动态填充的表。每一行都有一个打开模态的按钮,但是为了将参数传递给模态:首先,我在当前页面(products.php)上声明了模态。其次,我从另一个页面(modal.php)使用ajax调用了模态的其余部分。在使用ajax之前,我已经在select下拉列表中弹出了所有选项,但这次我似乎无法通过显示模式来完成同样的操作。我可以使用php href,但这会导致我在model上提交数据库时使用的jquery脚本不再工作,这就是为什么我想到通过ajax这

我有一个页面(products.php),其中有一个动态填充的表。每一行都有一个打开模态的按钮,但是为了将参数传递给模态:首先,我在当前页面(products.php)上声明了模态。其次,我从另一个页面(modal.php)使用ajax调用了模态的其余部分。在使用ajax之前,我已经在select下拉列表中弹出了所有选项,但这次我似乎无法通过显示模式来完成同样的操作。我可以使用php href,但这会导致我在model上提交数据库时使用的jquery脚本不再工作,这就是为什么我想到通过ajax这样做。我想知道为什么这不适用于ajax

下面是一个示例代码:

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>

函数模态值(val1,val2){
if(window.XMLHttpRequest){
xhttp=newXMLHttpRequest();
}否则{
xhttp=新的ActiveXObject(“Microsoft.XMLHTTP”);
}
xhttp.onreadystatechange=函数(){
如果(xhttp.readyState==4&&xhttp.status==200){
document.getElementById(“此处加载”).innerHTML=xhttp.responseText;
}
};
open(“POST”、“modal.php?id3=“+val1+”&id=“+val2,true”);
xhttp.send();
}

您需要更正以下两行,然后您的模型html就会出现:
xhttp.open(“POST”,“test2.php?id3=“+val1+”&id=“+val2,true”)非xhttp

echo”
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</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>