加载程序在 google chrome 中的同步(异步:假)ajax 调用期间不工作。在 Firefox 和 IE 中工作正常。在我的调试测试期间,Loader 显示直到 ajax 请求开始。当请求发送到服务器时被删除或消失,我在服务器上保存了一个调试点。我尝试过其他解决方案,例如使用 ajaxStart、beforeSend 和 ajax loader 等,但没有用。请给出有效的解决方案
<div id="LoaderDiv" style="display: none">
<img id="ImageLoader" src="Images/loading.gif" />
</div>
$('#LoaderDiv').show();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: servicePath,
async: false,
success: function (data) {
console.log(data.d);
$('#LoaderDiv').hide();
}
});
即使使用 async: false,我也面临着去年同样的问题。终于得到了一个最好的解决方案,但不确定它是否适用于你的情况,它对我有用 101%。
下面是代码:-
$.ajax({
.. ,
beforeSend: function () { showLoader(); },
success: function (data) { hideLoader(); }
});
function showLoader() {
$("#progressbar").css("display", "");
}
function hideLoader() {
setTimeout(function () {
$("#progressbar").css("display", "none");
}, 1000);
}
您可以使这两个函数在任何常见的 javascript 文件中通用。这样你就可以在多个地方或js文件中调用这些函数。
HTML 是:
<div class="spinnermodal" id="progressbar" style="display: none; z-index: 10001">
<div style="position: fixed; z-index: 10001; top: 50%; left: 50%; height:65px">
<img src="~/Images/loading.gif" alt="Loading..." />
</div>
</div>
Css is:
.spinnermodal {
background-color: #FFFFFF;
height: 100%;
left: 0;
opacity: 0.5;
position: fixed;
top: 0;
width: 100%;
z-index: 100000;
}
尝试这个。我希望它也对你有用。快乐编码:-)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)