PHP在modal中加载数据

PHP在modal中加载数据,php,mysql,modal-dialog,Php,Mysql,Modal Dialog,我需要使用发送到模式窗口的ID从数据库表加载数据 基本上,当网格加载时,会有多个柱。其中两个特别称为容器ID和工作流 为工作流返回的任何内容都将是一个链接,该链接将打开一个名为#mysvcmodel的模式弹出窗口。以下是示例代码: while(($Row = mysql_fetch_assoc($QueryResult)) !== FALSE) { echo "<tr"; echo "<td style=\"width: 50px;\">{$Row[CONTAI

我需要使用发送到模式窗口的ID从数据库表加载数据

基本上,当网格加载时,会有多个柱。其中两个特别称为容器ID和工作流

为工作流返回的任何内容都将是一个链接,该链接将打开一个名为#mysvcmodel的模式弹出窗口。以下是示例代码:

 while(($Row = mysql_fetch_assoc($QueryResult)) !== FALSE)
 {
   echo "<tr";
   echo "<td style=\"width: 50px;\">{$Row[CONTAINER_ID]}</td>";
   echo "<td style=\"width: 50px;\"><a class=\"open-container\" 
             data-toggle=\"modal\" href="#mySVCModal\" 
             data-cont=\"{$Row[CONTAINER_ID]}\">{$Row[WORKFLOW]}</a></td>";
   echo "</tr>";
 }
while(($Row=mysql\u fetch\u assoc($QueryResult))!==FALSE)
{

echo“听起来您需要一个AJAX查询

<script>
function loadData()
{
  var xmlhttp;
  if (window.XMLHttpRequest)
  {
    xmlhttp = new XMLHttpRequest();
  }
  else
  {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function()
  {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {
      document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET", "db_query.php?containerID = " + document.getElementById('containerID').getAttribute('value'), true);
  xmlhttp.send();
}
window.onload = loadData;
</script>

<div id="myDiv"></div>

函数loadData()
{
var-xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
}
其他的
{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“myDiv”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,“db_query.php?containerID=“+document.getElementById('containerID')).getAttribute('value'),true);
xmlhttp.send();
}
window.onload=加载数据;

对于任何可能的缺陷,我事先表示歉意,我并没有实际运行此操作。

在加载模板时,您似乎没有实际向服务器提交表单

由于您可能不希望重新加载整个页面以显示模式,因此应该使用异步请求按需请求模式内容。由于您的示例代码使用jQuery,因此我在这里使用了相同的方法。()

echo”
$(文档)。在(\“单击\”,\“.open Container\”,函数()上{
var myContainer=$(this.data('cont');
$(\“.modal body#containerID\”).val(myContainer);
$('.modal body').load(
“yourPHPscript.php”,
{containerID:$('#containerID').val()}
);
});
";
然后,您的PHP脚本应该与此类似(注意从POST到GET的更改):



此处缺少一个
echo”OP正在使用jQuery,为什么不直接使用
$.get()
 <div id="mySVCModal">
   <form action="" method="POST">
     <input type="text" name="containerID" id="containerID" class="containerID" />
   *** more code here ***
   </form>
 </div>
 <?php
 $containerID = $_POST['containerID'];
 echo "this is containerID " . $containerID;  // only displays the text, not the $containerID
 ?>
<script>
function loadData()
{
  var xmlhttp;
  if (window.XMLHttpRequest)
  {
    xmlhttp = new XMLHttpRequest();
  }
  else
  {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function()
  {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {
      document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET", "db_query.php?containerID = " + document.getElementById('containerID').getAttribute('value'), true);
  xmlhttp.send();
}
window.onload = loadData;
</script>

<div id="myDiv"></div>
echo "<script type=\"text/javascript\">
          $(document).on(\"click\", \".open-Container\", function() {
              var myContainer = $(this).data('cont');
              $(\".modal-body #containerID\").val( myContainer );
              $('.modal-body').load(
                  'yourPHPscript.php', 
                  { containerID: $('#containerID').val()}
              );
          });
       </script>";
<?php
 $containerID = $_GET['containerID'];
 echo "this is containerID " . $containerID;
 ?>