我有以下代码,它向我显示查询中的人员记录。我想通过post函数发送一个隐藏表单的id_Persona,并发送到页面idsPersonas.php只是缓存id_Persona
我是这样做的:
<tr class='clickable-row' onclick="post('/idsPersonas.php/',{ids: <?php "$lista[id_Persona];" ?>});">
并将我发送到未定义的页面
这是我的代码:
<table id="example" cellspacing="0" width="100%">
<thead class="text-primary">
<tr >
<th class="cabezera"><center><h4>Fecha</h4></center></th>
<th class="cabezera"><center><h4>Hora</h4></center></th>
<th class="cabezera"><center><h4>Nombre</h4></center></th>
</tr>
</thead>
<?php
if(count($listado)> 0 ){
foreach($listado as $lista)
{
$cuenta++;
?>
<tbody>
<tr class='clickable-row' onclick="post('/idsPersonas.php/',{ids: <?php "$lista[id_Persona];" ?>});">
<td><?php printf("%s",$lista["Fecha"]); ?></td>
<td><?php printf("%s",$lista["Hora"]); ?></td>
<td><?php printf("%s",$lista["Nombre"]); ?></td>
</tr>
<?php
}
}else {
?>
<h3> No hay </h3>
<?php
}//fin else
//printf($cuenta_eventos);
?>
</tbody>
</table>
JS:
function post(path, params, method) {
method = method || "post"; // Set method to post by default if not specified.
console.log(method);
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
答案 0 :(得分:0)
您将引号放在错误的位置。 它应该是这样的:
{ids: '<?php echo $lista['id_Persona']; ?>'});">