views:

584

answers:

1

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.

+2  A: 

with

type="text.javascript"

My opera and IE8 did not show alert

it should be

type="text/javascript"
S.Mark
Thanks! I was struck by code blindness.
Matt Ellen