LaravelOnly LaravelOnly - 3 months ago 54
Javascript Question

SweetAlert showLoaderOnConfirm not displaying

i am using sweetalert to display delete confirmation,and process it later while displayin a loading action,though it is not working,thi is the code,that doesn't work (it is supposed to display a loading animation,but it actually is not doing so) any thoughts ?

This the javascript

document.querySelector('div.test').onclick = function() {
swal({
title: 'Ajax request example',
text: 'Submit to run ajax request',
type: 'info',
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
}, function(){
setTimeout(function() {
swal('Ajax request finished!');
}, 2000);
});
};


Html

<div class="test">
<button>show alert</button>
</div>


this is the fiddle

Answer

I assume your include files are wrong (old for instance).

The snippet:

$(function () {
  $('div.test').on('click', function (e) {
    swal({
      title: "Ajax request example",
      text: "Submit to run ajax request",
      type: "info",
      showCancelButton: true,
      closeOnConfirm: false,
      showLoaderOnConfirm: true,
    }, function () {
      setTimeout(function () {
        swal("Ajax request finished!");
      }, 2000);
    });
  })
});
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<link href="https://rawgit.com/t4t5/sweetalert/master/dist/sweetalert.css" rel="stylesheet">
<script src="https://rawgit.com/t4t5/sweetalert/master/dist/sweetalert.min.js"></script>

<div class="test">
    <button>show alert</button>
</div>