【问题标题】:JSON = "XXX is Null or not an Object" in ie6, ie7 (not ie8, FF, Ch)JSON = "XXX is Null or not an Object" in ie6, ie7 (not ie8, FF, Ch)
【发布时间】:2010-07-26 07:10:58
【问题描述】:

为什么我在 ie6 和 ie7 中使用 json 时出现错误,而其他浏览器却没有?

我正在解析:

$.getJSON('http://www.brettbarros.com/wordpress/?post_type=projects&json=get_post&include=title,content,attachments&post_id=8', function(data) {
    alert(data);
});

我正在解析来自 wordpress 插件 JSON API 的 json 提要: http://wordpress.org/extend/plugins/json-api/other_notes/

您可以在此处查看测试/错误:http://brettbarros.com/ietest.html

编辑 2:“数据”似乎为空。我不知道为什么。

编辑 3:这是我的标题...有人看到它们有什么问题吗?如果是这样,我将如何解决它?

Date    Mon, 26 Jul 2010 08:31:11 GMT
Server  Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.7a mod_fcgid/2.3.5 Phusion_Passenger/2.2.15 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By    PHP/5.2.13
X-Pingback  http://brettbarros.com/wordpress/xmlrpc.php
Content-Disposition attachment; filename="json_api.json"
Vary    Accept-Encoding
Content-Encoding    gzip
Content-Length  719
Keep-Alive  timeout=5, max=98
Connection  Keep-Alive
Content-Type    application/json; charset=UTF-8

【问题讨论】:

  • 查看请求的标头,它们在告诉你什么。
  • GET /wordpress/?post_type=projects&json=get_post&include=title%2Ccontent%2Cattachments&post_id=8 HTTP/1.1[CRLF] 主机:www.brettbarros.com[CRLF] 连接:close[CRLF] User-代理:Web-sniffer/1.0.36 (+web-sniffer.net/)[CRLF] Accept-Encoding: gzip[CRLF] Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7[CRLF] Cache-控制:no[CRLF] Accept-Language:de,en;q=0.7,en-us;q=0.3[CRLF]Referer:web-sniffer.net/[CRLF]
  • 在您更改 Internet Explorer 7 中的代码之前,我获得了美伊关系项目或类似项目。
  • 谢谢安德斯。我现在已经在ie7中工作了,但不是ie6。这是一个说明 json 文件未加载的测试页面:brettbarros.com/ietest.html

标签: javascript jquery json


【解决方案1】:

Javascript 引擎在附件中看不到 url 属性的接缝。因此,如果您期望那里有一个 url 属性,而这仅在 IE6 和 IE7 中不起作用,则 JSON 请求的执行不会顺利。也许参数不正确或者id在浏览器中不是一个好的值?

id 设置在哪里?

您是否调试 JSON 请求以查看是否在每个浏览器中设置了 id

也许您可以提供更多信息?

【讨论】:

  • 我不确定,但我认为这可能与我正在调用的实际 json 文件或我如何调用它有关? ie6/7 需要 .js 结尾吗?
  • 我添加了一个网址供您测试
  • 只需在 $.getJSON( 之前放置一个 alert(id) 以查看是否设置了 id。我认为设置 id 是问题。处理 JSON 请求是在服务器端......似乎没有任何问题。我在这里得到了很好的回应
  • 感谢 michael,但我什至尝试对 id 进行硬编码,但还是不行。
  • 啊哈!这是子域 www 具有跨域问题 id 错误的组合。谢谢十亿:)
猜你喜欢
  • 2022-01-21
  • 2022-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-03
  • 1970-01-01
相关资源
最近更新 更多