我有以下代码,我正在使用块ui,但它不会阻塞页面。我正在使用ajax调用来获得用户控件结果(部分视图),以便在page.during ajax调用中加载到div中,我想使用blockui来阻止整个页面。
$('#btnGO').click(function() {
if (validate()) {
alert("loading");
$.blockUI({ message: '<img src="/Content/images/ajax-loader.gif"/>' }); //this is not working
$.ajax({
type: "POST",
url: "/Controller/action/", //to get the partial view
async: false,
cache: false,
beforeSend: function() {
},
complete: function() {
alert("ajax complete event")
$.unblockUI();
},
data: $('#frmPassBook').serialize(),
error: function(xhr, status, error) {
$('#ErrorMessage').html(xhr.responseText);
$("#ErrorMessage").stop().show('slow');
$('#ui-widget').show();
$.unblockUI();
},
success: function(data) {
$("#aCBDetails").parent().show();
$("#divCBDetails").hide("blind");
$("#aCBDetails span:first").removeClass("ui-icon-circle-triangle-n").addClass("ui-icon-circle-triangle-s");
$('#ui-widget').hide();
//loading html in div
$("#div").html(data);
if ($("#rbMain") != undefined) {
if ($("#rbMain").attr("checked")) {
$(".subTrId").hide();
$("#spSub").hide();
$("#spMain").show();
}
else {
$(".subTrId").show();
$("#spSub").show();
$("#spMain").hide();
}
} else {
$("#spSub").show();
$("#spMain").hide();
}
//unblocking after div is loaded with html
$.unblockUI();
}
});
} else {
$.unblockUI();
}
return false ;
});发布于 2012-08-27 21:34:53
使用baseZ索引来阻塞整个页面,例如。
$.blockUI({
message: "<img src="/Content/images/ajax-loader.gif"/>",
baseZ: 9000,
css: {
top: ($(window).height() - 400) /2 + "px",
left: ($(window).width() - 400) /2 + "px",
width: "400px"}
}); 发布于 2012-08-27 21:23:23
尝试使用jQuery的ajaxStart和ajaxStop方法。这些将使您能够在ajax调用启动时应用装载器,并在调用结束时将其移除。
https://stackoverflow.com/questions/12142746
复制相似问题