[英]ajax request modal ordering with bootstrap
我想在我的应用程序中全局使用模式窗口,因此在jquery的ajax complete和ajax start配置上进行设置。 我遇到一个问题,其中从ajax成功回调中调用的模式窗口与我的ajax通知模式冲突,因为它们未按我想要的顺序执行。
在此演示中,我希望它先警告1再警告2再警告3,但它首先执行成功处理程序...
$(document).ajaxStart(function(){
alert("1")
$("#first").modal("show")
})
$(document).ajaxComplete(function(){
alert("2")
$("#first").modal("hide")
})
$.get('./',function(d, e){
alert("3")
// now the problem is the previous modal has not
// yet fully dismissed
$("#second").modal("show")
})
如何触发ajaxComplete函数,并在执行任何回调函数之前删除通知模态,而回调函数本身可能会创建模态窗口?
为什么他们不是为了你想要执行的原因是在jQuery的文档( http://api.jquery.com/ajaxComplete/ , http://api.jquery.com/ajaxStart/ )
AjaxStart事件在您的ajax请求实现之前触发。
AjaxComplete事件在您的ajax完成实现之后触发。
$(document).ajaxStart(function(){
alert("AjaxStart");
});
$(document).ajaxComplete(function(){
alert("AjaxComplete");
});
$.get('./',function(d, e){
alert("Get A Start")
}).done(function(){
alert("Get A Done");
});
$.get('./',function(d, e){
alert("Get B Start")
}).done(function(){
alert("Get B Done");
});
因此,如果您运行此小提琴( http://jsfiddle.net/KbzCk/ ),您将看到正确的执行顺序。
如果您使用的是Bootstrap 3模式,请尝试检查“事件”部分
$('#modal-id').on('hidden.bs.modal', function () {
//show another modal
})
即使显示这么多模态窗口似乎也不是一种好方法。
如果仅将模式用于通知,请尝试使用toastr: http : //www.johnpapa.net/toastr100beta/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.