$(document).ready(function (){
$('#Delete').on('click', function() {
var no = $('#bill').val();
if(confirm('Are you sure to remove this record ?'))
{
$.ajax({
url: "<?php echo base_url();?>TipUp_Loan/Bill_Delete"+no,
type: 'DELETE',
error: function() {
alert('Something is wrong');
},
success: function(data) {
// $("#"+no).remove();
alert("Record removed successfully");
}
});
}
});
});
这是查看页面代码。。。
public function Bill_Delete(){
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
//$Search = $this->input->post('Search1');
$this->User_model->Bill_Delete($_POST["no"]);
}
此控制器代码。。。。。。。。。。。
public function Bill_Delete($no)
{
$this->db->where('billno', $no);
$this->db->delete('salesitem');
$this->db->where('no', $no);
$this->db->delete('salesbill');
echo "Successfully delete";
}
这是型号代码
我的prblm是如何创建确认消息的。这只是显示消息,它不会删除到数据库中。。。。。。。。。。。。。。
您可以通过在按钮标签中添加此window.confirm来实现这一点
<button type="submit" class="btn btn-primary" onclick="return confirm('Are you sure want to delete')">Delete<i class="icon-bin position-left"></i></button>
修改:
问题是您没有在AJAX调用中发送变量"no"的值。使用Jquery AJAX的"data"属性发送变量。此外,请使用类型:"post"进行AJAX调用。这是修改后的代码:
$(document).ready(function (){
$('#Delete').on('click', function() {
var no = $('#bill').val();
if(confirm('Are you sure to remove this record ?'))
{
$.ajax({
url: "<?php echo base_url();?>TipUp_Loan/Bill_Delete",
type: 'POST',
data: { no: no },
error: function() {
alert('Something is wrong');
},
success: function(data) {
alert("Record removed successfully");
}
});
}
});
});
在你的控制器内部:
public function Bill_Delete(){
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
//$Search = $this->input->post('Search1');
$this->User_model->Bill_Delete($_REQUEST["no"]);
}
剩下的就可以用你的模型和控制器了。我认为混合JS和PHP的方式看起来很难看,正如ThisGuyHasTwoThumbs所建议的那样。
我有另一个答案
<button type="submit" id="Delete" onclick="return confirm('Are You sure want to Delete')" class="btn btn-primary" >Delete<i class="icon-bin position-left"></i></button>
通过使用这个可以确认框已经启用