Mar*_*lny 8 jquery internet-explorer json
我很难让这个脚本工作.它基本上是一个简单的ajax调用,用于从php中检索返回JSON代码的数据.
function refreshWindows(){
if(AjaxPull && AjaxPull.readystate != 4){
AjaxPull.abort();
}
AjaxPull = $.ajax({
type: 'POST',
url: $path,
data: {
ajax: true,
mode: 'update',
to: Math.round(currentDate.getTime() / 1000),
from: Math.round(previousDate.getTime() / 1000)
},
dataType: "json",
success: function (data) {
alert(data); //that's for debug
$replies = data.Updates;
$.each($replies ,function(group,value) {
if (value!=''){
$("#group"+group+" .content").append(value);
$("#group"+group+" .content").stop().animate({ scrollTop: $("#group"+group+" .content")[0].scrollHeight }, 800);
if (!$("#group"+group+" .Window").is(':visible')) {
$("#group"+group+" .BottomBox").fadeTo('fast', 0.5).fadeTo('fast', 1.0);
}
}
});
previousDate = currentDate;
currentDate = new Date();
timeController.push( setTimeout(function(){refreshChatWindows();}, 500) );
}
});
Run Code Online (Sandbox Code Playgroud)
}
我在Internet Explorer中遇到的错误是:
SCRIPT5007:无法获取属性'Updates'的值:object为null或undefined
在Firefox和谷歌浏览器中一切正常.
最初我的代码是使用.get编写的,但有人建议切换到.ajax - 好吧,它没有帮助.我尝试过使用,.done(function(data){但它也没用.我也尝试在我的URL中发送与该data属性相反的所有数据,它在FF中工作正常,但IE仍然弹出相同的错误.最后,我尝试向PHP添加不同的标头,例如,header('Content-Type: application/json');但它没有改变任何东西.我没有想法/可能的解决方案我可以在stackoverflow上做好,所以任何帮助将不胜感激.
在IE中,我访问了开发人员工具,网络选项卡,并尝试查看是否一切正常 - 是的,请求正在使用所有数据正确发送,我收到的响应是正确的JSON,就像在Firefox中一样:
{"Updates":{"1":"","2":"","3":"","5":"","6":"","7":"","8":""},"time":{"from":"1367489761","to":"1367489761"}}
Run Code Online (Sandbox Code Playgroud)
这让我感到非常困惑,因为我一直认为Undefined错误可能只是因为某些东西因为某种原因没有在IE中被发回而发生,但很明显:事实并非如此.我得到了我的JSON.只有IE出于某种未知原因仍然认为数据未定义.
好吧,我终于找到了解决方案。基本上:
}).done(function ( data ) {而不是success: function (data) {就这样。突然它开始起作用了。这很奇怪。看起来霰弹枪策略(随机改变代码片段直到它起作用)实际上是解决问题的有效方法。呵呵呵呵
| 归档时间: |
|
| 查看次数: |
3828 次 |
| 最近记录: |