删除记录之前使用javascript自定义对话框.但是不知道如何通过js发送php值



显示来自cart 的N条记录

<a href='delete.php?id=<?php echo $id; ?>'>Delete</a>

这是用于删除特定记录的url。

在删除记录之前,我写了一个自定义的js对话框。

但我不知道如何将php-id值传递给delete.php

在下面的代码中,无论我点击哪里,它都只发送第一条记录的id,而不是正确的记录。

function Confirm(title, msg, $true, $false, $link) { /*change*/
var $content = "<div class='dialog-ovelay'>" +
"<div class='dialog'><header>" +
" <h3> " + title + " </h3> " +
"<i class='fa fa-close'></i>" +
"</header>" +
"<div class='dialog-msg'>" +
" <p> " + msg + " </p> " +
"</div>" +
"<footer>" +
"<div class='controls' style='text-align:right'>" +
" <button class='button button-danger doAction'>" + $true + "</button> " +
" <button class='button button-default cancelAction'>" + $false + "</button> " +
"</div>" +
"</footer>" +
"</div>" +
"</div>";
$('body').prepend($content);
$('.doAction').click(function() {
$(this).parents('.dialog-ovelay').fadeOut(500, function() {
location.href = "duplicate_frame.php?id=<?php echo $id; ?>";
$(this).remove();
});
});
$('.cancelAction, .fa-close').click(function() {
$(this).parents('.dialog-ovelay').fadeOut(500, function() {
$(this).remove();
});
});
}
$('.linkdup').click(function() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
Confirm('Are you sure you want to Duplicate Frame', 'One more frame will be added to Cart', 'Yes', 'No', ); /*change*/
});

这是非常糟糕的做法<a href='delete.php?id=<?php echo $id; ?>'>Delete</a>-蜘蛛的一次访问忽略了您的自定义确认,将擦除您的数据库

所以你需要这样做:

<button type="button" class="delete" data-id="<?php echo $id; ?>">Delete</button>

然后你可以做

let currentLink = ""
$('.delete').on('click',function() {
const id  = $(this).data("id");
currentLink = "delete.php?id="+id;
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
Confirm('Are you sure you want to delete item','This will delete '+id, 'Yes', 'No'); 
});

并具有

$('.doAction').click(function() {
$(this).parents('.dialog-ovelay').fadeOut(500, function() {
location.href = currentLink;
$(this).remove(); // does this even execute?
});
});

相关内容

最新更新