Php symfony 1.4和jquery。如何将变量传递给jquery函数?
我有一个带有AJAX函数的indexSuccess.php模板:Php symfony 1.4和jquery。如何将变量传递给jquery函数?,php,jquery,ajax,symfony-1.4,Php,Jquery,Ajax,Symfony 1.4,我有一个带有AJAX函数的indexSuccess.php模板: <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('#test<?php $mensajes->getIdmensajes() ?>').click(function(){ jQuery('#contenido<?php $mensajes->getI
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#test<?php $mensajes->getIdmensajes() ?>').click(function(){
jQuery('#contenido<?php $mensajes->getIdmensajes() ?>').load(this.href);
return false;
});
});
</script>
<h2>Listado de mensajes emitidos</h2>
<h3>En orden cronológico inverso (más nuevo primero)</h3>
<table id="enviados" width="60%" border="1" cellpadding="8">
<thead>
<tr>
<th>Fecha Creación</th>
<th>Contenido del mensaje</th>
<th>Destinatarios</th>
</tr>
</thead>
<tbody>
<?php foreach ($mensajess as $mensajes): ?>
<tr>
<td width="10%" align="center"> <?php echo date('d/m/Y', strtotime($mensajes->getFechaalta())) ?></td>
<td bgcolor="<?php echo $mensajes->getColores()->getCodigo() ?>"><?php echo $mensajes->getCuerpo() ?></td>
<td width="20%" id="contenido<?php echo $mensajes->getIdmensajes() ?>">
<a id="test<?php echo $mensajes->getIdmensajes() ?>" href="<?php echo url_for('mensajes/receptores?idmensajes='.$mensajes->getIdmensajes()) ?>">Ver receptores</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
我想将值$message->getIdmensajes传递给AJAX函数。我将为每一行使用不同的ID,但这不起作用。但是当我设置值时,函数运行良好。例如:jQuery'test24'和jQuery'contenido24'适用于Idmensajes=24的值。如何将$message->getIdmensajes值传递给AJAX函数?您的问题不太清楚,但您写了
jQuery ('#contenido24') works well for the value Idmensajes=24
还有,你有这个
jQuery('#test<?php $mensajes->getIdmensajes() ?>').click(function(){
jQuery('#contenido<?php $mensajes->getIdmensajes() ?>').load(this.href);
return false;
});
jQuery'contenido'+this.id.match/\d+/[0]将根据a的id选择id为contenido24、contenido25的元素,如果a标记的id为test20,则它将选择contenido20并将ajax调用的内容加载到此元素中。问题已解决!他的解决方案很有效。非常感谢你。你已经明白我想要什么了。再次非常感谢!
jQuery(document).ready(function(){
// Register click handler for all a tags whose id begins with 'test'
jQuery("a[id^='test']").click(function(e){
e.preventDefault(); // instead of return false
jQuery('#contenido'+this.id.match(/\d+/)[0]).load(this.href);
});
});