亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 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 關注
  • 127 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號