【问题标题】:Passing variable with button (Ajax Modal)使用按钮传递变量(Ajax 模式)
【发布时间】:2014-11-20 01:14:30
【问题描述】:

在表中(包含来自我的数据库的记录、客户凭据)我对每一行都有一个 删除 按钮。
我希望如果我点击删除按钮,这将删除该行,将记录的 ID 传递给 deletecustomer.php
当我单击删除按钮时,我有一个 ajax 模式询问您是否要确认操作。
问题是,如果我单击 CONFIRM(在模式中),我的模式将进入 delete-utente.php (其中我有删除行的查询)但 ID 没有传递。
在 delete-utente.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']; 

对不起,如果是愚蠢的错误或愚蠢的问题^^" 并感谢您的建议

【问题讨论】:

    标签: javascript php jquery ajax button


    【解决方案1】:

    你可以这样使用:

    <?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";
    
            });
        };
    

    【讨论】:

      【解决方案2】:

      试试下面的代码:

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

      【讨论】:

      • 感谢您的回答:)
      猜你喜欢
      • 1970-01-01
      • 2020-01-23
      • 2014-12-15
      • 2014-01-24
      • 2019-03-06
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 2023-01-24
      相关资源
      最近更新 更多