我对bootbox.js模式有疑问,正在执行并等待响应就绪状态更改为3,模型将显示但在请求完成且就绪状态更改为4后,在console.log中正在打印“ readystate 4”,但模型不会隐藏
var dialog = bootbox.dialog({
message: '<p class="text-center mb-0"><i class="fa fa-spin fa-cog"></i> Please wait while we do something...</p>',
className: 'bounceInUp animated',
closeButton: false,
show: false
});
// ready stat with jquery
var _orgAjax = jQuery.ajaxSettings.xhr;
jQuery.ajaxSettings.xhr = function () {
var xhr = _orgAjax();
xhr.onreadystatechange = function() {
console.log(xhr.readyState);
var state = xhr.readyState;
if (state == 3 ) {
dialog.modal('show');
console.log('readystate 3 ');
}else if (state == 4) {
dialog.modal('hide');
console.log('readystate 4 ');
};
}
return xhr;
};
您可以通过选项beforeSend
在ajax请求中使用它,并在ajax完成后始终将其关闭。
$.ajax({
beforeSend: function() {
dialog.modal('show'); <------------------ HERE show before
},
method: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
.always(function( msg ) {
dialog.modal('show'); <----------------- HERE hide always on finish
});