I have a page that works fine in Firefox 3.5.6, but not in IE 7 or Opera 10.01
I have included a mini version of JSON2.js from json.org in the script tag in the chapter section.
In Firefox, data is parsed into an object. Opera and IE throw errors saying they cannot find the JSON object.
How can I fix my javascript so that IE and Opera find a JSON object?
EDIT
The script tag looks like this:<script type="text.javascript" language="javascript" src="script/json2min.js"></script>
The code is similar to
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 get in 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
Line 188 var messageData = JSON.parse(result);
In IE 7, I get an error
Line: 189
Char: 4
Error: 'JSON' is undefined
Code: 0
URL: http://mojohub/ideaweb/messages.php
Data in resultequal
{"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 line breaks.