我在我的有这个功能actions.class.php
:
public function executeIndex(sfWebRequest $request) {
$id_empresa = $this->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
$this->records = Doctrine_Core::getTable('SdrivingRegistrosEmisores')
->createQuery('re')
->leftJoin('re.SdrivingTurno t')
->leftJoin('re.SdrivingMaquinaEmisor me')
->leftJoin('me.SdrivingMaquina m')
->leftJoin('re.SdrivingOperador o')
->leftJoin('re.SdrivingDetalleEmisores de')
->where('o.idempresa = ?', $id_empresa)
->execute();
}
呈现此视图:
<table class="table table-condensed table-striped table-hover table-bordered pull-left" id="data-table">
<thead>
<tr>
<th><?php echo __('Turno') ?></th>
<th><?php echo __('ID Máquina') ?></th>
<th><?php echo __('Operador') ?></th>
<th><?php echo __('Semáforo') ?></th>
<th> </th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $record): ?>
<tr>
<td><?php echo $record->SdrivingTurno->getTipo(); ?></td>
<td><?php echo $record->SdrivingMaquinaEmisor->SdrivingMaquina->getPatente(); ?></td>
<td><?php echo $record->SdrivingOperador->getNombre() ?></td>
<td>
<?php
if (count($record->SdrivingDetalleEmisores) > 0):
if ($record->SdrivingDetalleEmisores->getFirst()->getRevisado() == 0):
echo image_tag('bullet_red.png');
elseif ($record->SdrivingDetalleEmisores->getFirst()->getRevisado() == 1):
echo image_tag('bullet_orange.png');
endif;
else:
echo image_tag('bullet_green.png');
endif;
?>
</td>
<td><?php echo link_to('Ver detalles', 'ver-detalles/' . $record->getIdregistros(), 'class="btn btn-success btn-mini"') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
正如标题所说,我需要每 10 秒重新加载一次表格内容,在 Stackoverflow 和 Google 中挖掘我发现了这个主题,我可以在其中获取 jQuery 代码,但我的问题是:如何更新表格 HTML 元素中的每一行?
编辑
阅读推荐后,用户将我留在这里,这是我迄今为止尝试过的,但没有成功:
actions.class.php
public function executebuildAjax(sfWebRequest $request) {
$id_empresa = $this->getUser()->getGuardUser()->getSfGuardUserProfile()->getIdempresa();
$records = Doctrine_Core::getTable('SdrivingRegistrosEmisores')
->createQuery('re')
->leftJoin('re.SdrivingTurno t')
->leftJoin('re.SdrivingMaquinaEmisor me')
->leftJoin('me.SdrivingMaquina m')
->leftJoin('re.SdrivingOperador o')
->leftJoin('re.SdrivingDetalleEmisores de')
->where('o.idempresa = ?', $id_empresa)
->execute();
echo '<table class="table table-condensed table-striped table-hover table-bordered pull-left" id="data-table">';
echo '<thead>';
echo '<tr>';
echo '<th>' . __('Turno') . '</th>';
echo '<th>' . __('ID Máquina') . '</th>';
echo '<th>' . __('Operador') . '</th>';
echo '<th>' . __('Semáforo') . '</th>';
echo '<th></th>';
echo '</tr>';
echo '<tbody>';
foreach ($records as $record):
echo '<tr>';
echo '<td>' . $record->SdrivingTurno->getTipo() . '</td>';
echo '<td>' . $record->SdrivingMaquinaEmisor->SdrivingMaquina->getPatente() . '</td>';
echo '<td>' . $record->SdrivingOperador->getNombre() . '</td>';
echo '<td>';
if (count($record->SdrivingDetalleEmisores) > 0):
if ($record->SdrivingDetalleEmisores->getFirst()->getRevisado() == 0):
echo image_tag('bullet_red.png');
elseif ($record->SdrivingDetalleEmisores->getFirst()->getRevisado() == 1):
echo image_tag('bullet_orange.png');
endif;
else:
echo image_tag('bullet_green.png');
endif;
echo '</td>';
echo '<td>' . link_to('Ver detalles', 'ver-detalles/' . $record->getIdregistros(), 'class="btn btn-success btn-mini"') . '</th>';
echo '</tr>';
endforeach;
echo '</tbody>';
echo '</thead>';
echo '</table>';
}
indexSuccess.php
看法:
<div id="dt_example" class="example_alt_pagination"></div>
<script>
$(document).ready(function() {
setInterval(function() {
$.ajax({
type: 'get',
url: '<?php echo url_for('dashboard/buildAjax') ?>',
datatype: 'html',
success: function(data) {
$("#dt_example").html(data);
},
error: function() {
alert('<?php echo __('Error loading data!!!') ?>');
}
});
}, 10000);
});
</script>
但我总是收到警告框错误加载数据!!!为什么?怎么了?