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.

avatar Query
@Query

61 Kontribusi 6 Poin

Diperbarui 5 tahun yang lalu

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

avatar maszgalang
@maszgalang

297 Kontribusi 80 Poin

Dipost 5 tahun yang lalu

gan sory, kalo untuk proses click button nya gimana gan ?

avatar Query
@Query

61 Kontribusi 6 Poin

Dipost 5 tahun yang lalu

<pre> $(".cuks").click(function(){} </pre>

pada $(".cuks"). itu kan ada ".cuks" itu class dari button tersebut juga bisa diganti dengan id

avatar maszgalang
@maszgalang

297 Kontribusi 80 Poin

Dipost 5 tahun yang lalu

ini coding class nya gan,

<pre> &lt;a class="btn btn-danger" id="hapus" onclick="hapus('delete.php?&id=&lt;?php echo $b['id']; ?&gt;');"&gt;&lt;span class="fa fa-trash"&gt;&lt;/span&gt;&lt;/a&gt; </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

avatar Query
@Query

61 Kontribusi 6 Poin

Dipost 5 tahun yang lalu

kalau menggunakan

<pre> onclick="hapus('delete.php?&id=&lt;?php echo $b['id']; ?&gt;');" </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

avatar maszgalang
@maszgalang

297 Kontribusi 80 Poin

Dipost 5 tahun yang lalu

problemnya di script perintah nya gan

<pre> &lt;a class="btn btn-danger" onclick="hapus('delete.php?&id=&lt;?php echo $b['id']; ?&gt;');"&gt;&lt;span class="fa fa-trash"&gt;&lt;/span&gt;&lt;/a&gt; </pre>

avatar Query
@Query

61 Kontribusi 6 Poin

Dipost 5 tahun yang lalu

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.

avatar maszgalang
@maszgalang

297 Kontribusi 80 Poin

Dipost 5 tahun yang lalu

Login untuk ikut Jawaban