通过按钮传递变量(Ajax Modal)
Passing variable with button (Ajax Modal)
在表(包含我的数据库中的记录、客户凭据)中,每行都有一个删除按钮
我希望如果我点击删除按钮,这将删除行,并将记录的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>'; ?>
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- 如何通过ajax刷新JSF填充的javascript变量
- 如何在php文件中获取$.post-ajax传递的值
- Replacing $ .ajax?
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- Ajax发布表单序列化,发布引号'
- Jquery Modal表单登录与AJAX-ASP经典上的IE 9
- 只有当有AJAX响应时,Bootstrap Modal才会出现
- 将函数绑定到Twitter Bootstrap Modal Ajax Complete
- 传递数据以填充在ajax Modal中加载的输入字段
- 带有Modal/Overlay Ajax内容的Google分析页面视图
- BootStrap Django Jquery Modal在Ajax调用提交时未关闭
- 如何使用ajax从modal提交表单
- 使用ajax和验证时关闭Modal
- Bootstrap Modal init and AJAX
- 通过按钮传递变量(Ajax Modal)
- Rails 5 Bootstrap 3 Modal / Ajax not working
- 向jQuery Modal发送ajax成功响应
- BootStrap Modal + JS/AJAX 复选框表单提交