我正在使用jquery ajax在单击链接时将单独的页面加载到模式窗口中。当模式内容加载时,我有一个显示的加载图像。加载图片位于页面上的div中,并显示页面上的任何ajax加载。这一切都正常工作,但我似乎无法让图像隐藏在ajax调用成功后。jQuery ajax加载图像不隐藏
这里是我使用jQuery:
$('#loadingImage').ajaxStart(function(){
$(this).show();
});
$('#loadingImage').ajaxSuccess(function(){ //also tried ajaxStop
$(this).hide();
});
function loadMap(){
$('#whereweare-map').click(function(){
$('#lightBox').removeClass().addClass('reveal-modal expand');
$.ajax({
url: '/Map#mapLoad',
success: function(data){
$('#lightBox').reveal();
$('#lightBoxContent').html(data);
}
});
return false;
});
}
loadMap();
HTML:
<div id="imageLoading"></div>
<a href="#" id="whereweare-map">Where We Are</a>
<div class="reveal-modal" id="lightBox">
<div id="lightBoxContent"><!-- Load Content Here --></div>
<a class="close-reveal-modal">×</a>
</div>
而CSS:
#loadingImage {
display:none;
height:84px;
width:84px;
position:fixed;
top:50%;
left:50%;
z-index: 1;
background: url('preloader.gif') no-repeat center center;
background-color: #000;
background-color: rgba(0, 0, 0, 0.7);
-moz-border-radius:45px;
-webkit-border-radius:45px;
border-radius:45px;
}
感谢您的帮助。
我会说这是更好地使用ajaxComplete – Felix
刚试过用ajaxComplete,它也没有工作。 – eCamK