Php Sweetalert2删除确认
我想用codeigniter中的sweetalert2进行删除确认,但我不知道如何进行,有人能帮我吗 这是sweetalert2脚本Php Sweetalert2删除确认,php,codeigniter,sweetalert2,Php,Codeigniter,Sweetalert2,我想用codeigniter中的sweetalert2进行删除确认,但我不知道如何进行,有人能帮我吗 这是sweetalert2脚本 <script src="<?php echo base_url(); ?>sweetalert2/dist/sweetalert2.all.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/promise-polyfill"&g
<script src="<?php echo base_url(); ?>sweetalert2/dist/sweetalert2.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill"></script>
<script src="<?php echo base_url(); ?>sweetalert2/dist/sweetalert2.min.js"></script>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/sweetalert2/dist/sweetalert2.min.css">
<script type="text/javascript">
function hapus() {
event.preventDefault();
var form = event.target.form;
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}
})}
</script>
试试这个
swal.fire({
title: 'Are you sure?',
text: "Are you sure you want to proceed ?",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes'
}).then(function(result) {
if (result.value) {
$.ajax({
url : 'enter your url',
type : 'POST',
data : {id:id },
dataType:'json',
beforeSend: function() {
swal.fire({
title: 'Please Wait..!',
text: 'Is working..',
onOpen: function() {
swal.showLoading()
}
})
},
success : function(data) {
swal.fire({
position: 'top-right',
type: 'success',
title: 'User deleted successfully',
showConfirmButton: false,
timer: 2000
});
},
complete: function() {
swal.hideLoading();
},
error: function(jqXHR, textStatus, errorThrown) {
swal.hideLoading();
swal.fire("!Opps ", "Something went wrong, try again later", "error");
}
});
}
});
这是控制器
function hapus($id){
$where = array('id' => $id);
$this->m_data->hapus_data($where,'blogs');
redirect('Postingan');
}
function hapus($id){
$where = array('id' => $id);
$this->m_data->hapus_data($where,'blogs');
//echo true; OR return true;
}
试试这个
function hapus($___id) {
swal.fire({
title: 'Are you sure?',
text: "Are you sure you want to proceed ?",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes'
}).then(function(result) {
if (result.value) {
$.ajax({
url : `postingan/hapus/${$__id}`,
type : 'GET',
dataType:'json',
beforeSend: function() {
swal.fire({
title: 'Please Wait..!',
text: 'Is working..',
onOpen: function() {
swal.showLoading()
}
})
},
success : function(data) {
swal.fire({
position: 'top-right',
type: 'success',
title: 'User deleted successfully',
showConfirmButton: false,
timer: 2000
});
},
complete: function() {
swal.hideLoading();
},
error: function(jqXHR, textStatus, errorThrown) {
swal.hideLoading();
swal.fire("!Opps ", "Something went wrong, try again later", "error");
}
});
}
});
}
按钮
<button onclick="hapus(<?php echo $b->id; ?>)" style="width:70px"type="button" class="btn btn-block btn-outline-danger">Hapus</button>
Jangan lupa包含jQuery
基拉-基拉·斯佩蒂尼
函数hapus($\uuuuu id){
喷火({
标题:“你确定吗?”,
文本:“您确定要继续吗?”,
键入:“警告”,
showCancelButton:true,
confirmButtonText:“是”
}).then(函数(结果){
if(result.value){
$.ajax({
url:`postingan/hapus/${$\uu id}`,
键入:“GET”,
数据类型:'json',
beforeSend:function(){
喷火({
标题:“请稍候…”,
文本:“正在工作…”,
onOpen:function(){
swal.showLoading()
}
})
},
成功:函数(数据){
喷火({
位置:'右上',
键入:“成功”,
标题:“用户已成功删除”,
showconfixton:false,
计时器:2000
});
},
完成:函数(){
swal.hideLoading();
},
错误:函数(jqXHR、textStatus、errorshown){
swal.hideLoading();
swal.fire(“!Opps”,“出现问题,请稍后再试”,“错误”);
}
});
}
});
}
Hapus
我想试着回答,因为现在我用sweet alert confirm删除数据时遇到了同样的问题。所以我使用ajax(post)和work的方法
首先在按钮中获取id数据
控制器删除
模型删除
我希望这个答案能帮助你是的,你的钮扣有问题吗?数据出错了,链接url:
postingan/hapus/${$\uu id}
```
<button onclick="hapus(<?php echo $b->id; ?>)" style="width:70px"type="button" class="btn btn-block btn-outline-danger">Hapus</button>
<button onclick="hapus(<?php echo $b->id; ?>)" style="width:70px"type="button" class="btn btn-block btn-outline-danger"><?php echo 'Hapus'); ?></button>
function del(id){
Swal.fire({
title: 'Yakin menghapus?',
text: "Data yang sudhah dihapus tidak dapat dikembalikan!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya, hapus sekarang!'
}).then((result) => {
if (result.value) {
Swal.fire({
title: 'Terhapus!',
text: 'Data berhasil dihapus.',
icon: 'success',
showConfirmButton: false
});
$.ajax({
type:"POST",
url: "back/rule/kontak_blog/del", //url function delete in controller
data:{
id:id //id get from button delete
},
success:function(data){ //when success will reload page after 3 second
window.setTimeout( function(){
location.reload();
}, 300 );
}
});
}
})
}
function del() {
$id = $this->input->post('id'); //get data from ajax(post)
$del = $this->M_kontak_blog->del($id);
}
function del($id) {
$this->db->where('kb_id', $id);
$this->db->delete(' tb_kontak_blog');
}