IE 7 或 Opera 10.01 无法识别 JSON2.js

发布于 2024-08-16 22:20:46 字数 1587 浏览 10 评论 0原文

我有一个页面可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安人多梦 2024-08-23 22:20:46

type="text.javascript"

的歌剧和 IE8 没有显示警报,

应该是

type="text/javascript"

with

type="text.javascript"

My opera and IE8 did not show alert

it should be

type="text/javascript"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文