Postingan lainnya
Membuat Alert Notifikasi dengan sweetalert
hallo gan. ane punya script di bawah ini :
<script type="text/javascript">
function JSalert(){
swal({ title: "Your account will be deleted permanently!",
text: "Are you sure to proceed?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Remove My Account!",
cancelButtonText: "No, I am not sure!",
closeOnConfirm: false,
closeOnCancel: false },
function(isConfirm){
if (isConfirm)
{
swal("Account Removed!", "Your account is removed permanently!", "success");
}
else {
swal("Hurray", "Account is not removed!", "error");
} });
}
</script>
lalu cara membuat script php nya gimana ya gan ?
Mohon bantuannya master. Terima kasih.
7 Jawaban:
itu mau dipasang ketika click button, atau waktu proses dijalankan ?
kalau mau nampilin via onclick(), gak perlu php, karena ketika di click otomatis proses itu dijalankan.
<pre>
$(document).ready(function(){
$(".cuks").click(function(){
var det = $("#datas").val();
$.ajax({
type: 'POST',
url: 'hapus.php?id='+det,
success: function(data) {
swal({ title: "Your account will be deleted permanently!",
text: "Are you sure to proceed?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Remove My Account!",
cancelButtonText: "No, I am not sure!",
closeOnConfirm: false,
closeOnCancel: false },
function(isConfirm){
if (isConfirm)
{
swal("Account Removed!", "Your account is removed permanently!", "success");
}
else {
swal("Hurray", "Account is not removed!", "error");
} });
}
}
});
});
});
</pre>
itu untuk POST ke contoh saja, karena untuk delete data kan pasti perlu id user atau yang lainya, coba dipelajari lagi
gan sory, kalo untuk proses click button nya gimana gan ?
<pre> $(".cuks").click(function(){} </pre>
pada $(".cuks"). itu kan ada ".cuks" itu class dari button tersebut juga bisa diganti dengan id
ini coding class nya gan,
<pre> <a class="btn btn-danger" id="hapus" onclick="hapus('delete.php?&id=<?php echo $b['id']; ?>');"><span class="fa fa-trash"></span></a> </pre>
Script Javascript nya :
<pre> $(document).ready(function(){
$(".hapus").click(function(){
var det = $("#datas").val();
$.ajax({
type: 'POST',
url: 'hapus.php?id='+det,
success: function(data) {
swal({ title: "Your account will be deleted permanently!",
text: "Are you sure to proceed?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Remove My Account!",
cancelButtonText: "No, I am not sure!",
closeOnConfirm: false,
closeOnCancel: false },
function(isConfirm){
if (isConfirm)
{
swal("Account Removed!", "Your account is removed permanently!", "success");
}
else {
swal("Hurray", "Account is not removed!", "error");
} });
}
}
});
});
}); </pre>
notif nya masih gak muncul gan
kalau menggunakan
<pre> onclick="hapus('delete.php?&id=<?php echo $b['id']; ?>');" </pre>
brarti bukan menggunakan itu
tapi menggunakan
<pre>
function hapus(value){
var det = value;
$.ajax({
type: 'POST',
url: 'hapus.php?id='+det,
success: function(data) {
swal({ title: "Your account will be deleted permanently!",
text: "Are you sure to proceed?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Remove My Account!",
cancelButtonText: "No, I am not sure!",
closeOnConfirm: false,
closeOnCancel: false },
function(isConfirm){
if (isConfirm)
{
swal("Account Removed!", "Your account is removed permanently!", "success");
}
else {
swal("Hurray", "Account is not removed!", "error");
} });
}
}
});
});
});
}
</pre>
kalau blm bisa coba di inspect element masuk ke console, dan network, di screenshot apa problemnya
problemnya di script perintah nya gan
<pre> <a class="btn btn-danger" onclick="hapus('delete.php?&id=<?php echo $b['id']; ?>');"><span class="fa fa-trash"></span></a> </pre>
iy kalau menggunakan
<pre> onclick="hapus()" </pre>
maka harusnya di jquerynya menggunakan
<pre> function hapus(value){} </pre>
tidak menggunakan
<pre> $(document).ready(function(){ $(".hapus").click(function(){ var det = $("#datas").val(); </pre>
karena kalau menggunakan script diatas itu mengambil data dari input, button, link, dengan class/id yang ada pada component tersebut.