所以,我有一個 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個贊
href
解決方案:在 jQuery 中僅使用“&”附加屬性。你需要一個“?” 而不是“&”。解決方案:您將 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')
}
- 1 回答
- 0 關注
- 127 瀏覽
添加回答
舉報
0/150
提交
取消