IE 7 或 Opera 10.01 无法识别 JSON2.js
我有一个页面可以在 Firefox 3.5.6 中正常工作,但不能在 IE 7 或 Opera 10.01 中工作,我包含来自 json.org 位于 head 部分的脚本标记中。在 Firefox 中,数据被解析为一个对象。 Opera 和 IE 都会抛出错误,表示找不到 JSON 对象。
如何修复我的 JavaScript,以便 IE 和 Opera 都能找到 JSON 对象?
编辑: 脚本标签如下所示:
<script type="text.javascript" language="javascript" src="script/json2min.js"></script>
代码类似于
function readMessageEnd()
{
if(this.readyState == 4)
{
var result = this.responseText;
var messageData = JSON.parse(result);
... do stuff with messageData;
}
}
readMessageEnd()
是异步 AJAX 调用的回调函数。
我在 Opera 中收到的错误消息是:
JavaScript - http://mojohub/ideaweb/messages.php
Unknown thread
Error:
name: ReferenceError
message: Statement on line 188: Undefined variable: JSON
stacktrace: n/a; see opera:config#UserPrefs|Exceptions Have Stacktrace
第 188 行是 var messageData = JSON.parse(result);
在 IE 7 中,我收到错误
Line: 189
Char: 4
Error: 'JSON' is undefined
Code: 0
URL: http://mojohub/ideaweb/messages.php
The data in result
是
{"from_name":"matt"
,"subject":"testing stuff"
,"body":"Yo. I'm testing how this system works.<br \/>\n<br />\nInit."
,"private_message_id":"2"
,"message_status":"Read"
,"avatar_url":"http:\/\/url_goes_here"
,"status_update":false}
但没有换行符。
I have a page that's working fine in Firefox 3.5.6 but not in IE 7 or Opera 10.01
I'm including the minified version of JSON2.js from json.org in a script tag in the head section.
In Firefox the data gets parsed into an object. Opera and IE both throw errors, saying they can't find the JSON object.
How can I fix my javascript so that IE and Opera both find the JSON object?
EDIT
The script tag looks like: <script type="text.javascript" language="javascript" src="script/json2min.js"></script>
The code is something like
function readMessageEnd()
{
if(this.readyState == 4)
{
var result = this.responseText;
var messageData = JSON.parse(result);
... do stuff with messageData;
}
}
readMessageEnd()
is a callback function for an asynchronous AJAX call.
The error message I am getting in Opera is:
JavaScript - http://mojohub/ideaweb/messages.php
Unknown thread
Error:
name: ReferenceError
message: Statement on line 188: Undefined variable: JSON
stacktrace: n/a; see opera:config#UserPrefs|Exceptions Have Stacktrace
Line 188 is var messageData = JSON.parse(result);
In IE 7 I'm getting the error
Line: 189
Char: 4
Error: 'JSON' is undefined
Code: 0
URL: http://mojohub/ideaweb/messages.php
The data in result
is
{"from_name":"matt"
,"subject":"testing stuff"
,"body":"Yo. I'm testing how this system works.<br \/>\n<br />\nInit."
,"private_message_id":"2"
,"message_status":"Read"
,"avatar_url":"http:\/\/url_goes_here"
,"status_update":false}
But without the line breaks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我
的歌剧和 IE8 没有显示警报,
应该是
with
My opera and IE8 did not show alert
it should be