admin管理员组

文章数量:1289507

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

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

Share Improve this question asked Aug 21, 2016 at 18:14 MrRobotMrRobot 5011 gold badge7 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Sweetalert is unsupported anymore. You might want to switch to sweetalert2:

Swal.fire({
  title: 'Ajax request example',
  text: 'Submit to run ajax request',
  icon: 'info',
  showCancelButton: true,
  showLoaderOnConfirm: true,
  preConfirm: function() {
    return new Promise(function(resolve, reject) {
      // here should be AJAX request
      setTimeout(function() {
        resolve();
      }, 1000);
    });
  },
}).then(function() {
  Swal.fire('Ajax request finished!');
});
<script src="https://cdn.jsdelivr/npm/sweetalert2@11"></script>

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./jquery-1.12.4.min.js"></script>
<link href="https://rawgit./t4t5/sweetalert/master/dist/sweetalert.css" rel="stylesheet">
<script src="https://rawgit./t4t5/sweetalert/master/dist/sweetalert.min.js"></script>

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

本文标签: javascriptSweetAlert showLoaderOnConfirm not displayingStack Overflow