我正在尝试将一个变量发送到一个模态的pint但我得到注意:未定义的变量:ordID
我搜索了许多其他请求,但没有解决我的问题。
我的代码: 带有a的表用于显示将包含该行的所有信息的模态。
<table id="myTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID Ordem</th>
<th>Instalação</th>
<th>Denominação</th>
<th>Estado</th>
<th>Tipo de Manut</th>
<th>Ver</th>
</tr>
</thead>
<tbody>
<?php
require_once 'edp/configdbedp.php';
$sql="SELECT * FROM ordens";
//echo $sql;
$myData=mysqli_query($GLOBALS['con'],$sql);
while($registos=mysqli_fetch_array($myData)){
$ordem = $registos['ordem'];
echo '<tr>';
echo '<td>' . $registos['ordem'] . '</td>';
echo '<td>' . $registos['locinstsap'] . '</td>';
echo '<td>' . $registos['denominacao'] . '</td>';
echo '<td>' . $registos['pk_idestado'] . '</td>';
echo '<td>' . $registos['pk_sigla'] . '</td>';
echo '<td align="center"><a id="getUser" class="modalLink" href="#myModal" data-toggle="modal" data-target="#myModal" data-id="<?php echo $ordem; ?>"><span class="glyphicon glyphicon-edit"></span> Ver</a></td>';
echo "</tr>";
}
//mysqli_close($GLOBALS['con']);
?>
</tbody>
</table>
我要通过POST发送的脚本:
<script>
$('.modalLink').click(function(){
var ordem=$(this).data('id');
$.ajax({
type:'POST',
url:'/edp/php/adm/modalordens.php',
data:'ordID='+ordem,
success:function(data){
$(".modal-content").html(data);
}
});
});
</script>
我的档案modalordens.php
<? $ordID = $_POST['ordID'];?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="fam_id">Ordem <?php echo $ordID;?></h4>
</div>
<div class="modal-body">
<form id="form1" method="post">
<b>DetailsOrdem <?php echo $ordID;?></b>
<hr></hr>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
我无法打印 $ ordID ,我不知道为什么
答案 0 :(得分:3)
首先,您需要将ajax数据参数作为对象传递:
namespace DiscordBot
{
class MyBot : ModuleBase
{
private CommandService _service;
public MyBot(CommandService service)
{
_service = service;
}
}
}
在此行上编辑 php开场标记:
<script>
$('.modalLink').click(function(){
var ordem=$(this).data('id');
$.ajax({
type:'POST',
url:'/edp/php/adm/modalordens.php',
data: { ordID : ordem },
success:function(data){
$(".modal-content").html(data);
}
});
});
</script>
答案 1 :(得分:2)
你的ajax帖子错了它应该是
$.ajax({
type:'POST',
url:'/edp/php/adm/modalordens.php',
data: {ordID : ordem},
success:function(data){
$(".modal-content").html(data);
}
});