繁体   English   中英

Bootbox dialog.modal('hide') 不隐藏模式?

[英]Bootbox dialog.modal('hide') doesn't hide modal?

我对 bootbox.js 模式有疑问。 Being executed and waiting for response ready State changed to 3 and model will show But after the request is complete and ready state changed to 4 and readystate 4 is printing in console.log but model doesn't hide.

    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({
  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
 });

您也可以像此链接一样使用$.ajaxSetup但从文档中不建议使用它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM