【发布时间】:2020-09-17 00:58:34
【问题描述】:
我有这段代码可以让我从 sql 数据库中获取数据。
代码表:
<table id="id_tabella" class="fold-table" align="center">
<thead>
<tr>
<th style="">Id</th>
<th>OrderCode</th>
<th>Partner</th>
<th>NrProdotti</th>
<th>Totale</th>
<th>Stato</th>
</tr>
</thead>
<tbody>
<?php
while( $result = sqlsrv_fetch_array($run_query,SQLSRV_FETCH_ASSOC))
{
if($result) {
?>
<tr id="<?php echo $result['Id']; ?>" class="view">
<td style=""><?php echo $result['Id']; ?></td>
<td><?php echo $result['OrderCode']; ?></td>
<td><img align="middle" src="<?php echo $result['Img']?>" width="10%"></td>
<td><?php echo $result['NrProdotti']; ?></td>
<td><?php echo $result['TotaleOrdine']; ?></td>
<td>
<form method="POST" action="">
<input name = "idOrdine" value="<?php echo $result['Id'] ?>" type="submit">
</form>
</td>
</tr>
<tr class="fold">
<td colspan="6">
<div class="fold-content">
<h3>DETTAGLIO ORDINE</h3>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
<table>
<thead>
<tr>
<th>Dettaglio Ordine:</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<?php
$data = json_decode($result['JsonOrdine'], true);
foreach($data['products'] as $key=>$val){
echo '<b>'.$val['name'].' * '.$val['quantity'].'</b><br>';
foreach($val['attributes'] as $keys=>$value){
echo $value['name'].' * '.$value['quantity'].'<br>';
}
}
?>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr><?php } } sqlsrv_free_stmt($run_query);?>
</tbody>
我无法让页面底部的 js 脚本与代码一起使用:
alert(ultimo);
代码 JS:
<script>
$(document).ready(function(){
setInterval(newNoti, 5000);
function newNoti(){
//var ultimo = $('#id_tabella tr').last().attr("Id");
var ultimo = $('#id_tabella tr').last().attr("Id");
alert(ultimo);
$.ajax({
type: "post",
url: "o_accoda.php",
data: {'last_id': ultimo},
success:function(resp){
if(resp != ""){
$("#audio")[0].play();
$('#c_id_tabella').append(resp);
var rowCount = $('#c_id_tabella').find('tr').length-1;
//$("#id_tabella").append(resp);
//var rowCount = $('#id_tabella').find('tr').length-1;
$('#demo').html("ORDINI IN ARRIVO: " + rowCount);
}
},
error:function(){
alert('Some problem occured, please try again.');
}
})
}
});
</script>
它返回“未定义”
【问题讨论】:
-
你总是以 TR 元素结尾:
。此元素没有任何 id 属性。检查你的 while 循环。
标签: javascript html accordion