2016-08-21 152 views
1

我使用sweetalert來顯示刪除確認,稍後在顯示加載操作時處理它,儘管它不工作,thi是代碼,不起作用(它應該顯示加載動畫,但實際上並沒有這樣做)有什麼想法?SweetAlert showLoaderOnConfirm不顯示

這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> 

這是fiddle

回答

3

我假設你的包含文件是錯誤的(舊的實例)。

的片段:

$(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>

+0

謝謝,你這樣做有問題,我不知道我的,包括是錯誤的,因爲它的工作幾乎是罰款,但謝謝你的提示(順便說一句jquery與我的數據表發生衝突,所以我根本沒有使用它,使用我的1.12.3 jQuery)謝謝你的提示救了我 – LaravelOnly

1

Sweetalert是不支持了。也許,你可能想切換到sweetalert2

swal({ 
    title: 'Ajax request example', 
    text: 'Submit to run ajax request', 
    type: 'info', 
    showCancelButton: true, 
    showLoaderOnConfirm: true, 
    preConfirm: function() { 
    return new Promise(function(resolve, reject) { 
     // here should be AJAX request 
     setTimeout(function() { 
     resolve(); 
     }, 2000); 
    }); 
    }, 
}).then(function() { 
    swal('Ajax request finished!'); 
}).done(); 

[JSFIDDLE]