$(文件).ready不在IE中加载

时间:2013-05-08 15:59:43

标签: javascript jquery internet-explorer document-ready

我有一个网址,它为我提供了我需要的各种参数。我已经设法得到了结果,但由于某种原因,它在IE中根本没有显示任何结果,我不知道为什么。它适用于所有其他浏览器,但不是IE。我已经检查了控制台,并且没有任何错误,我也使用jslint.com检查js代码,这一切都很好。

我已删除了文件中的所有其他内容,因此只有此内容。

这就是我用来获得结果的方法。我有一个单独的js文件,其中包含:

function call(url, parameters, callback) {
"use strict";
$.ajax({
type: 'POST',
url: url,
data: parameters,
success: function(data) {
callback(data);
}
}
);
}

function loadJackpots() {
"use strict";
call("https://www.domain.com/passkey", { JL: 0 },
function(data) {
var divIdentifier, obj = eval('(' + data + ')');
$.each(obj.JL, function() {
divIdentifier = "";
switch (this.gameID) {
case 2:
divIdentifier = "#snap";
break;
case 5:
divIdentifier = "#dominos";
break;
case 1000:
divIdentifier = "#chess1";
break;
case 1001:
divIdentifier = "#chess2";
break;
case 1002:
divIdentifier = "#chess3";
break;
}

if (this.gameID >= 1000) {
switch (this.stakeID) {
case 4:
divIdentifier += "_50c";
break;
case 5:
divIdentifier += "_1d";
break;
case 7:
divIdentifier += "_2d";
break;
case 9:
divIdentifier += "_2d";
break;
}

if (this.gameID === 1000) {
switch (this.subID) {
case 0:
divIdentifier += "_1";
break;
case 1:
divIdentifier += "_2";
break;
case 2:
divIdentifier += "_3";
break;
}
}
$(divIdentifier).html("$" + this.jackpot);
});
}
);
}

我用它来实际加载值:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript"> 
$(document).ready(function() {
loadJackpots();
});    

</script>

要显示我正在使用的结果:

<div id="chess1">
<script type="text/javascript">
                    document.write('<div id="chess1_50c">');
</script>$1466.85</div>
<script type="text/javascript">
                    document.write('<div id="chess1_1d">');
</script>$1641.11</div>
<script type="text/javascript">
    document.write('<div id="chess1_2d">');
</script>$378.04</div>
</div>  


<div id="chess3">
<script type="text/javascript">
    document.write('<div id="chess3_50c">');
</script>$303.86</div>
<script type="text/javascript">
    document.write('<div id="chess3_1d">');
</script>$523.02</div>
<script type="text/javascript">
    document.write('<div id="chess3_2d">');
</script>$1473.72</div>
</div>

</div>
<div style="float: left; margin: 194px 0 0 185px;">
<div id="chess2_1">
<script type="text/javascript">
    document.write('<div id="chess2_50c_1">');
            </script>$195.26</div>
                <script type="text/javascript">
    document.write('<div id="chess2_1d_1">');
</script>$154.37</div>
<script type="text/javascript">
    document.write('<div id="chess2_2d_1">');
</script>$193.76</div>
</div>
<div id="chess2_2">
<script type="text/javascript">
    document.write('<div id="chess2_50c_2">');
</script>$146.84</div>
<script type="text/javascript">
    document.write('<div id="chess2_1d_2">');
</script>$119.58</div>
<script type="text/javascript">
    document.write('<div id="chess2_2d_2">');
</script>$145.86</div>
</div>

<div id="chess2_3">
<script type="text/javascript">
    document.write('<div id="chess2_50c_3">');
</script>$2.96</div>
<script type="text/javascript">
    document.write('<div id="chess2_1d_3">');
</script>$19.25</div>
<script type="text/javascript">
    document.write('<div id="chess2_2d_3">');
</script>$121.89</div>
</div>

</div>
</div>

<div style="height: 80px;">
<div id="snap">
<script type="text/javascript">
    document.write('<div id="snap_jp">');
</script>$862.16</div>
</div>      

<div id="dominos">
<script type="text/javascript">
document.write('<div id="dominos_jp">');
</script>$2823.18</div>
</div>

我真的很感激任何有关这方面的帮助,因为我已经尝试了一切来对它进行排序,但无论我做什么它只是在IE中不起作用

我尝试使用

<script type="text/javascript">
$(document).ready(function() {
alert('test');
}
</script>

看看它是否正常加载,但它根本没有显示警告框 - 即使我删除了所有内容并且只有警报代码

3 个答案:

答案 0 :(得分:2)

语法错误:在结束时缺少)

$(document).ready(function() {
    alert('test');
});

答案 1 :(得分:0)

检查你的浏览器文档模式,你可能需要使用$(function(){而不是$(document).ready,我发现文件模式7和8有这个问题,你的浏览器可能会反驳到IE7文档模式,但在IE9窗口中运行.HIT F12 to findout。

REVISION

试试这个,你可能需要在你的Eval语句中添加一个忽略,因为它可能会让你的脚本中断。尝试添加到您的javascript顶部/ * jshint -W061 * /参见示例。

/*jshint -W061 */
function call(url, parameters, callback) {
"use strict";
$.ajax({
type: 'POST',
url: url,
data: parameters,
success: function(data) {
callback(data);
}
}
);
}

function loadJackpots() {
    "use strict";
call("https://www.domain.com/passkey", { JL: 0 },
function(data) {
var divIdentifier, obj = eval('(' + data + ')');
$.each(obj.JL, function() {
divIdentifier = "";
switch (this.gameID) {
case 2:
divIdentifier = "#snap";
break;
case 5:
divIdentifier = "#dominos";
break;
case 1000:
divIdentifier = "#chess1";
break;
case 1001:
divIdentifier = "#chess2";
break;
case 1002:
}

});        });     }

答案 2 :(得分:0)

我刚刚发现了问题所在。看起来因为Feed来自另一个服务器/域,它在IE中不起作用。我将feed保存为json文件,并将其保存在与站点相同的根文件夹中,并且运行良好。