通过按钮传递变量(Ajax Modal)

Passing variable with button (Ajax Modal)

本文关键字:Ajax Modal 变量 按钮      更新时间:2023-09-26

在表(包含我的数据库中的记录、客户凭据)中,每行都有一个删除按钮
我希望如果我点击删除按钮,这将删除行,并将记录的ID传递给deletecustomer.php
当我点击删除按钮时,我有一个ajax模式,询问您是否要确认操作
问题是,如果我点击CONFIRM(在模态中),我的模态将进入delete-utent.php(在那里我可以查询行的删除),但ID没有被传递
在delete-utent.php中,如果查询正常(删除完成),我会收到一条消息,如果无法完成删除,则会收到另一条消息
在我点击确认后,我总是收到OK消息,但该客户尚未被删除
我想问题不在于deletecustomer.php,因为如果我使用一个简单的javascript警报,查询就可以了,我成功地传递了标识符,但使用ajax模式,标识符就不会传递。

这是我第一次使用ajax,所以我认为问题在于ajax代码。

主页(newcustomer.php)中表格的代码

<table class="simple-table responsive-table" method="POST" id="customer-list">
//code thead
//rows rows..
<?php echo '<button type="input" class="button icon-trash with-tooltip confirm" onclick="openConfirm()" href="deletecustomer.php?customerid='.$idcustomer.'" title="Delete"></button>'; ?>
//....
</table>

ajax模式

function openConfirm()
        {
            $.modal.confirm('Sicuri di voler cancellare il cliente?', function()
            {
                window.location.href = "deletecustomer.php"; //the php file where I have the delete query

            }, function()
            {
                window.location.href = "newcustomer.php";
            });
        };

我在deletecustomer.php中获取值,如

$customeridd=(int) $_GET['customerid']; 

抱歉,如果这是一个愚蠢的错误或愚蠢的问题^^"感谢

的建议

您可以这样使用:

<?php 
  echo '<button type="input" class="button icon-trash with-tooltip confirm" onclick="openConfirm('.$idcustomer.')" href="deletecustomer.php?customerid='.$idcustomer.'" title="Delete">button</button>'; 
?>

function openConfirm(id)
    {
        alert(id);
        $.modal.confirm('Sicuri di voler cancellare il cliente?', function()
        {
            window.location.href = "deletecustomer.php?customerid="+id; //the php file where I have the delete query

        }, function()
        {
            window.location.href = "newcustomer.php";
        });
    };

尝试以下代码:

<?php echo '<a class="button icon-trash with-tooltip confirm" onclick="return confirm(''Are you sure?'');" href="deletecustomer.php?customerid='.$idcustomer.'">Delete</a>'; ?>