javascript - 如何通过POST方法以隐藏形式发送信息?

标签 javascript php jquery html mysql

我有以下代码,它显示了查询中的人员记录。我想通过 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();
}

最佳答案

您将引号放在了错误的位置。 它应该这样读:

{ids: '<?php echo $lista['id_Persona']; ?>'});">

关于javascript - 如何通过POST方法以隐藏形式发送信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46651108/

相关文章:

javascript - 检查带有原型(prototype)的 native 定义函数

javascript - jquery 禁用/删除选择选项?

jquery - 我如何使用 jquery 显示和隐藏这个加载栏

javascript - 检查数组是否包含特定字符串,然后选择该项目

javascript - 通过提交按钮将 PHP 转换为 JavaScript

php - Laravel 出现错误 : Call to undefined function table()!

javascript - 如何使用 Mootools 删除 “onclick”

php - mySQL blob 图像打印输出?

javascript - 从许多选择标签中选择一次删除选项

php - 编辑客户帐户时出现 Magento fatal error