为了账号安全,请及时绑定邮箱和手机立即绑定

使用 jquery 将带 href 的 ID 发送到 php 页面

使用 jquery 将带 href 的 ID 发送到 php 页面

PHP
弑天下 2024-01-19 15:09:29
所以,我有一个 CRUD 和一个按钮来修改,应该重定向到另一个带有该人的 id 的页面,我尝试用 jquery 这种方式来做到这一点    fetchList()function fetchList() {    $.ajax({        url: 'lista.php',        type: 'GET',        success: function (response) {            let task = JSON.parse(response);            let template = '';            task.forEach(task => {                template +=                    `<tr pacienteId="${task.id_pac}">                    <td>${task.apellido}  </td>                    <td>${task.nombre}</td>                    <td>${task.dni}</td>                    <td>${task.fecha_nacimiento}</td>                    <td>${task.fecha_ingreso}</td>                    <td>${task.obra_social}</td                    // <td <span class="badge pacActivo">Activo</span> </td>                    <td>                        <div class="btn-group btn-group-toggle d-flex justify-content-center">                        <a href="modificar.php" id="modificar" class="btn btn-sm butMod"></a>                                    <i class="fas fa-edit"></i>                            <button class="btn btn-sm butDel darBaja">                                <i class="fas fa-trash-alt"></i>                            </button>                        </div>                    </td>                </tr>`            });            $("#listadoPacientes").html(template);        }    });}这是修改    $(document).on('click', '#modificar', function (e) {    var href = $(this).attr('href');    let element = $(this)[0].parentElement.parentElement.parentElement    let id = $(element).attr('pacienteId')    // Save information    // Check if any ID is aviable     if (id) {        // Save the url and perform a page load         var direccion = href + '&id=' + id;        window.open(direccion);        console.log(id)    } else {        // Error handling        alert('algo salio mal')    }})但问题是我收到此错误:未定义索引:C:\xampp\htdocs\system\modules\Patients\modify.php 中的 id我在变量内有来自 jquery 的 ID
查看完整描述

1 回答

?
慕姐8265434

TA贡献1813条经验 获得超2个赞

  1. href解决方案:在 jQuery 中仅使用“&”附加属性。你需要一个“?” 而不是“&”。

  2. 解决方案:您将 GET 参数放在 jQuery HTML 构建过程href标记后面。

简而言之,您生成的 URL 如下: modificar.php&id=0 正确的是 modificar.php**?**id=0

例子:

if (id) {

        // Save the url and perform a page load

         var direccion = href + '?id=' + id; // changed the & to an ?

        window.open(direccion);

        console.log(id)


    } else {

        // Error handling

        alert('algo salio mal')

    }


查看完整回答
反对 回复 2024-01-19
  • 1 回答
  • 0 关注
  • 29 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信