Jquery IE 9中未显示ajax加载图标
由于某些原因,加载/微调器图标不会出现在IE中,但在Firefox中工作正常。你看到我的代码有什么错误吗 我的jQuery-Jquery IE 9中未显示ajax加载图标,jquery,html,css,Jquery,Html,Css,由于某些原因,加载/微调器图标不会出现在IE中,但在Firefox中工作正常。你看到我的代码有什么错误吗 我的jQuery- var loader = $('#loading'); loader.hide() .ajaxStart(function () { loader.show(); }) .ajaxStop(function () {
var loader = $('#loading');
loader.hide()
.ajaxStart(function () {
loader.show();
})
.ajaxStop(function () {
loader.hide();
});
我的HTML看起来像这样-
<div id="te">
......
<div id="container">
......
<div id="body-container">
......
<div id="loading">
<img alt="Loading, please wait.." src="/images/spinner.gif" />
</div>
</div>
</div>
</div>
更新#1:
已尝试从css中删除加载img的#te#loading
,并将加载的#te#loading
修改为此,但无效-
#te #loading { background-repeat: no-repeat; background-color: #F9F9F9; border: 1px solid #aaa; border-radius: 5px; left: 45%;top: 45%; padding: 20px 50px; position: fixed; z-index: 1000; }
更新#2:
这是我的js代码-
<script type="text/javascript">
$(function () {
var cpdata;
setupEvents();
loadInitialData();
function setupEvents() {
var loader = $('#loading');
loader.hide()
.ajaxStart(function () {
loader.show();
})
.ajaxStop(function () {
loader.hide();
});
// some other stuff..
}
function loadInitialData() {
cpdata = callMethod(urlLoadInitialData, {}, false);
if (cpdata != null) {
// do something with cpdata
}
}
function callMethod(url, parameters, async) {
var data;
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(parameters),
async: async,
contentType: 'application/json;',
dataType: 'json',
success: function (result) {
data = result.d;
}
});
return data;
}
});</script>
$(函数(){
var-cpdata;
setupEvents();
loadInitialData();
函数setupEvents(){
变量加载器=$(“#加载”);
loader.hide()
.ajaxStart(函数(){
loader.show();
})
.ajaxStop(功能(){
loader.hide();
});
//一些其他的东西。。
}
函数loadInitialData(){
cpdata=callMethod(urlLoadInitialData,{},false);
if(cpdata!=null){
//用cpdata做点什么
}
}
函数调用方法(url、参数、异步){
var数据;
$.ajax({
键入:“POST”,
url:url,
数据:JSON.stringify(参数),
异步:异步,
contentType:'应用程序/json;',
数据类型:“json”,
成功:功能(结果){
数据=结果d;
}
});
返回数据;
}
});
尝试稍微更改代码:
var loader = $('#loading');
loader.hide();
$.ajaxStart(function() {
loader.show();
});
$.ajaxStop(function() {
loader.hide();
});
备选方案:
jQuery(document).ready(function(){
jQuery('#loading').hide();
jQuery.ajaxStart(function() {
jQuery('#loading').show();
});
jQuery.ajaxStop(function() {
jQuery('#loading').hide();
});
});
另一种替代方法:使用complete:
jQuery(document).ready(function(){
jQuery('#loading').hide();
jQuery.ajaxStart(function() {
jQuery('#loading').show();
});
jQuery.ajaxComplete(function() {
jQuery('#loading').hide();
});
});
确保包括:
<meta http-equiv="X-UA-Compatible" content="IE=9" />
没有骰子。我在loader.show/hide之前放置了警报,它们显示得很好。但是加载程序不会显示代码>调用实际在
$(函数(){})
基本上与$(document).ready(function(){})相同代码>。我猜IE在固定位置上做了一些愚蠢的事情,并误解了这一点,将其放在屏幕外或下面。你用Firebug检查过元素行为吗?@JamieHartnoll:我删除了加载程序.hide()代码>在<代码> $.AjxStuts函数中,当我添加<代码> Load .Hiver()时,我可以在IE.的屏幕中部看到加载器。代码>返回,它不会显示。也尝试过移除固定位置。没有变化。尝试位置:绝对为#te#loading@Yorgo例如我已经试过了。仍然不起作用。你的js代码看起来不错。我认为loader会显示,但它会显示在一些其他元素(如div)下。设置z-indexe是否可以在img标记上指定背景图像?@ob-我也看到,同时使用img标记和背景可能有点过火-最好将背景图像放在div上,然后完全删除img标记。
<meta http-equiv="X-UA-Compatible" content="IE=9" />
$(function() {
var cpdata;
var loader = $('#loading');
loader.hide().ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
setupEvents();
loadInitialData();
function setupEvents() {
// some other stuff..
}
function loadInitialData() {
cpdata = callMethod(urlLoadInitialData, {}, false);
if (cpdata != null) { // do something with cpdata
}
}
function callMethod(url, parameters, async) {
var returnData;
var pString = JSON.stringify(parameters);
$.ajax({
type: 'POST',
url: url,
data: pString,
async: async,
contentType: 'application/json',
dataType: 'json',
converters: {
"json jsond": function(msg) {
return msg.hasOwnProperty('d') ? msg.d : msg;
}
},
success: function(result) {
returnData = result;
},
error: function(xhr, textStatus, errorThrown) {
var errorMessage = "Ajax error: " + this.url + " : " + textStatus + " : " + errorThrown + " : " + xhr.statusText + " : " + xhr.status;
if (xhr.status != "0" || errorThrown != "abort") {
alert(errorMessage);
}
if (errorThrown == "abort") {
alert("Aborted Ajax");
}
}
});
return returnData;
}
});