【发布时间】:2020-02-24 21:53:11
【问题描述】:
我一直在编写一些代码,一旦您单击按钮而不刷新整个页面,框就会消失,我无法克服当前的障碍。我的 AJAX 似乎没有发布任何数据,正如您从下面的代码中看到的那样,我有一个确认弹出窗口,它有效并且确实弹出,当您单击确定时,它应该将 ID 发布到 SQL 运行的另一个页面,但它没有,我已经尝试通过回显 POST 来测试它,看看它是否检索到它并且没有运气。
任何想法为什么它不会发布数据?
P.s 我已经检查过该功能是否正确,但在这里你可以看到用户点击了什么,并且 id 是 100% 的
<button onclick='good(<?= $appRow['customer_appointments_id']; ?>)' class='w3-button w3-block w3-green w3-section'><i class='fa fa-check'></i></button>
AJAX
function good(id){
if (confirm("Are you sure you want to complete this appointment?")) {
$.ajax({
type: "POST",
url: "scripts/lead/completeLeadTask.php",
data: ({
id: id
}),
cache: false,
success: function(html) {
$(".delete_mem" + id).fadeOut('slow');
}
});
Scripts/lead/completeLeadTask.php
echo $_POST['id'];
$stmt = $dbh->prepare("UPDATE `customer_appointments` SET `customer_appointments_status` = 'c' WHERE `customer_appointments`.`customer_appointments_id` = ?")->execute([$_POST['id']]);
$stmt = null;
【问题讨论】:
-
你能得到按钮点击的id吗????
-
我该如何测试?
-
功能良好(id){
alert(id); -
是的,这行得通。我得到了正确的 id