我一直在尝试使用由https://craftpip.github.io/jquery-confirm/#ajaxloading提供的jquery-confirm。没有错误,但是一旦我尝试删除一个项目,jquery会弹出一个警报,但是当我点击"好的"它没有删除项目..我不知道错误在哪里。谢谢你的帮助
这是php代码:
<div class="box">
<div class="box-body">
<a href="<?php echo base_url(); ?>admin/inputrequest" class="btn bg-green btn-flat">Input Request</a>
<br><br>
<table id="tabelrequest" class="table table-bordered table-striped">
<thead>
<tr>
<th>No.</th>
<th>Item Code</th>
<th>Description</th>
<th>Qty</th>
<th>Delete</th>
<th>Edit</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach($allrequest as $request)
{
$delete_url = base_url().'admin/deleterequest/'.$request->id_request;
$update_url = base_url().'admin/updaterequest/'.$request->id_request;
$add_url = base_url().'admin/datafotorequest/'.$request->id_request;
?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $request->item_code; ?></td>
<td><?php echo $request->description; ?></td>
<td><?php echo $request->qty; ?></td>
<td class="col-xs-1" style="text-align: center;"><a class="btn bg-olive btn-flat" class="delete" data-title="Are you sure you want to delete this item?" name="delete" href="<?php echo $delete_url; ?>"><i class="glyphicon glyphicon-trash"></i></a></td>
<td class="col-xs-1" style="text-align: center;"><a class="btn bg-teal btn-flat" name="update" href="<?php echo $update_url; ?>"><i class="glyphicon glyphicon-pencil"></i></a></td>
<td class="col-xs-1" style="text-align: center;"><a class="btn bg-red btn-flat" name="add" href="<?php echo $add_url; ?>"><i class="glyphicon glyphicon-camera"></i></a></td>
</tr>
<?php
$no++;
}
?>
</tbody>
</table>
</div>
</div>
这是我从jquery-confirms.js
获取的jquery<script>
$('#delete').confirm({
content: "",
});
$('#delete').confirm({
buttons: {
hey: function(){
location.href = this.$target.attr('href');
}
}
});
</script>
答案 0 :(得分:1)
我认为你必须像这样使用
<div class="box">
<div class="box-body">
<a href="<?php echo base_url(); ?>admin/inputrequest" class="btn bg-green btn-flat">Input Request</a>
<br><br>
<table id="tabelrequest" class="table table-bordered table-striped">
<thead>
<tr>
<th>No.</th>
<th>Item Code</th>
<th>Description</th>
<th>Qty</th>
<th>Delete</th>
<th>Edit</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
foreach($allrequest as $request)
{
$delete_url = base_url().'admin/deleterequest/'.$request->id_request;
$update_url = base_url().'admin/updaterequest/'.$request->id_request;
$add_url = base_url().'admin/datafotorequest/'.$request->id_request;
?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $request->item_code; ?></td>
<td><?php echo $request->description; ?></td>
<td><?php echo $request->qty; ?></td>
<td class="col-xs-1" style="text-align: center;"><a class="btn bg-olive btn-flat delete" data-title="Are you sure you want to delete this item?" name="delete" href="<?php echo $delete_url; ?>"><i class="glyphicon glyphicon-trash"></i></a></td>
<td class="col-xs-1" style="text-align: center;"><a class="btn bg-teal btn-flat" name="update" href="<?php echo $update_url; ?>"><i class="glyphicon glyphicon-pencil"></i></a></td>
<td class="col-xs-1" style="text-align: center;"><a class="btn bg-red btn-flat" name="add" href="<?php echo $add_url; ?>"><i class="glyphicon glyphicon-camera"></i></a></td>
</tr>
<?php
$no++;
}
?>
</tbody>
</table>
</div>
</div>
<script>
$('.delete').confirm({
content: "",
});
$('.delete').confirm({
buttons: {
hey: function(){
location.href = this.$target.attr('href');
}
}
});
</script>
答案 1 :(得分:1)
而不是这个
<td class="col-xs-1" style="text-align: center;">
<a class="btn bg-olive btn-flat" class="delete" data-title="Are you sure you want to delete this item?" name="delete" href="<?php echo $delete_url; ?>">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
我将使用(onclick="return confirm()"
)
<td class="col-xs-1" style="text-align: center;">
<a class="btn bg-olive btn-flat" class="delete" onclick="return confirm('Are you sure you want to delete this item?');" href="<?php echo $delete_url; ?>">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
答案 2 :(得分:0)
您需要创建ajax请求
HTML
<td class="col-xs-1" style="text-align: center;"><a class="btn bg-olive btn-flat" class="delete" data-title="Are you sure you want to delete this item?" name="delete" href="#" onclick="deleteRecord('<?php echo $request->id_request;?>');"><i class="glyphicon glyphicon-trash"></i></a></td>
AJAX
function deleteRecord(id)
{
jQuery.ajax({
type: "GET",
url: '/admin/deleterequest/'+id,
async: false,
success: function (data)
{
alert('success');
}
});
}