gpt4 book ai didi

json - jQuery 和 JSON 与 IE - SCRIPT5007 : Unable to get value of the property

转载 作者:行者123 更新时间:2023-12-03 22:33:30 28 4
gpt4 key购买 nike

我正在努力让这个脚本正常工作。它基本上是一个简单的 ajax 调用,用于从返回 JSON 代码的 php 检索数据。

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) );
}
});

}

我在 Internet Explorer 中遇到的错误是:

SCRIPT5007: Unable to get value of the property 'Updates': object is null or undefined

在 Firefox 和 Google Chrome 中一切正常。

最初我的代码是使用 .get 编写的但有人建议切换到 .ajax - 好吧,这没有帮助。我尝试使用 .done(function(data){ 但它也不起作用。我还尝试将 URL 中的所有数据发送到 data 属性对面,它在 FF 中工作正常,但 IE 仍然弹出相同的错误。最后我尝试向 PHP 添加不同的 header ,例如 header('Content-Type: application/json'); 但它没有不改变任何东西。我在 stackoverflow 上已经没有想法/可能的解决方案了,所以任何帮助将不胜感激。

在 IE 中,我转到“开发人员工具”的“网络”选项卡,并尝试查看是否一切正常 - 是的,请求与所有数据一起正确发送,并且我收到的响应是正确的 JSON,就像在 Firefox 中一样:

{"Updates":{"1":"","2":"","3":"","5":"","6":"","7":"","8":""},"time":{"from":"1367489761","to":"1367489761"}}

这让我真的很困惑,因为我认为未定义的错误可能只是因为无论出于何种原因没有在 IE 中发送回某些内容而发生,但显然:事实并非如此。我拿回了 JSON。只有 IE 由于某种未知原因仍然认为数据未定义。

最佳答案

好吧,我终于找到了解决办法。基本上:

  • 删除 PHP 脚本发送的所有 header 。特别是:内容类型 header 。 (幸运的是 - 似乎 session 仍然可以使用)
  • 使用 }).done(function ( data ) { 而不是 success: function (data) {

仅此而已。突然它开始起作用了。这很奇怪。看起来霰弹枪策略(随机改变代码片段直到它起作用)实际上是解决问题的有效方法。呵呵呵呵

关于json - jQuery 和 JSON 与 IE - SCRIPT5007 : Unable to get value of the property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16336297/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com