javascript - 使用带有 javascript 和 php 的确认框
问题描述
在删除发生之前,我需要包含一个确认框。我在这里和谷歌研究了这一切,找不到可行的选择,所以我希望有人能教我正确的方法来解决这个问题。
在引导程序中的表中显示删除按钮的函数...
function operateFormatter(value, row, index) {
return [
'<a class="remove" onclick="" href="deleteVendor.php?vendor_id=' + row.id + '" title="Remove">',
'<i class="fa fa-trash"></i>',
'</a>',
'<a class="view" href="viewVendor.php?vendor_id=' + row.id + '" title="View">',
'<i class="fa fa-eye"></i>',
'</a>'
].join('')
}
删除供应商.php
<?php
session_start();
/* Include the database connection file (remember to change the connection parameters) */
require './db_inc.php';
/* Include the Account class file */
require './account_class.php';
/* Create a new Account object */
$account = new Account();
$user = $_SESSION['username'];
$login = FALSE;
$id = $account->getIdFromName($user);
$vendor_id = $_GET['vendor_id'];
try
{
$login = $account->sessionLogin();
}
catch (Exception $e)
{
echo $e->getMessage();
die();
}
if ($login)
{
}
else
{
header('Location: ./index.php');
}
$query = "DELETE FROM vendors.vendor_data WHERE id=$vendor_id";
/* Execute the query */
try
{
$res = $pdo->prepare($query);
$res->execute();
}
catch (PDOException $e)
{
/* If there is a PDO exception, throw a standard exception */
throw new Exception($e);
}
?>
解决方案
您可以为此使用确认功能。
<a href="delete.php" onclick="return confirm('Are you sure?')">Click To Delete</a>
推荐阅读
- javascript - 如何以最小的复杂性从javascript中的数组中获取不匹配的数组值?
- java - 存储在 MongoDB 中的 JSON 包含 \,\r,\n 字符
- php - 如何在 php 扩展中获取请求标头
- python-3.x - 比较两个字典列表,如果键和值存在,则从列表中删除字典
- c++ - 概念约束模板函数调用的歧义
- firebase - Flutter、Redux 和 Firebase Auth Invalid argument(s) 错误
- jenkins - 如何从管道脚本触发远程作业
- java - Kafka Consumer 如何以及何时使用 Apache Camel 等 EIP 框架在 Kafka 中提交偏移量?我们如何使用 camel-kakfa 异步处理重试?
- ffmpeg - 如何组合两个 ffmpeg 命令
- python - Pandas groupby 对象唯一计数性能