所有这些代码都能工作。它激活BS5模式并使用MySQL db上的存储过程填充它的记录。问题是调用了错误的变量。如果您设置了一个“同步”变量,那么“等待”必须使用相同的变量(我的坏变量),或者破坏“承诺”函数。此外,为此,我必须将PDO输出放到单独的数组中,并使用PHP 'data.json‘on来捕获响应,并正确命名变量。一旦组织得当,它就能很好地运作。成功使用fetch-api。现在我可以使用fetch-api、pdo、存储过程和MySQL完成CRUD。
<?php
include "init.php";
$P1 = $_GET['userId'];
$stmt = $pdo->prepare("CALL readSingleUserSp(?)");
$stmt>bindParam(1,$P1,PDO::
PARAM_STR|PDO::PARAM_INPUT_OUTPUT|PDO::ATTR_EMULATE_PREPARES,
4000);
$stmt->execute(array($P1));
do {
$res = $stmt->fetchAll();
} while ($stmt->nextRowset() && $stmt->columnCount());
foreach ($res as $row) {
$userId = $row['userId'];
$fName = $row['fName'];
$lName = $row['lName'];
$email = $row['email'];
$phone = $row['phone'];
}
$userinfo = array( 'userId'=>$userId,
'fName' =>$fName,
'lName' =>$lName,
'email' =>$email,
'phone' =>$phone);
echo json_encode($userinfo);
?> const tbody = document.querySelector("tbody");
const addModal = document.getElementById("addNewUserModal");
const addForm = document.getElementById("add-user-form");
const updateForm = document.getElementById("edit-user-form");
// Edit User Ajax Request
tbody.addEventListener("click", (e) => {
if (e.target && e.target.matches("a.editLink")) {
e.preventDefault();
let userId = e.target.getAttribute("userId");
editUser(userId);
}
});
`const editUser = async (userId) => {
const data = await fetch(`includes/readsingleuser.php?
&userId=${userId}`, {
method: "GET",
});
const userinfo = await data.json();
document.getElementById("userIdEdit").value =
userinfo.userId;
document.getElementById("fNameEdit").value = userinfo.fName;
document.getElementById("lNameEdit").value = userinfo.lName;
document.getElementById("emailEdit").value = userinfo.email;
document.getElementById("phoneEdit").value = userinfo.phone;
};发布于 2022-04-24 15:04:49
“所有这些代码都能工作。它激活BS5模式并使用MySQL db上的存储过程填充它的记录。问题是调用了错误的变量。如果您设置了一个“同步”变量,那么“等待”必须使用相同的变量(我的坏变量),或者破坏“承诺”函数。此外,为此,我必须将PDO输出放入一个单独的数组中,并使用“Jason_encode”来捕获响应,并正确命名变量。一旦组织得当,它就会运作得很好。成功使用fetch-API。我现在可以使用fetch-API、pdo、存储过程和MySQL完成CRUD。“当Stack机器人抱怨时,我更改了原来的代码以缩短问题。
https://stackoverflow.com/questions/71946654
复制相似问题