Sign in to follow this  
Black Knight

[web] JSON file and IE

Recommended Posts

Hi,

I've downloaded this file :
http://www.json.org/json2.js

Added it to my index page before my own javascript file:
<script type="text/javascript" src="json.js"></script>

Then i try to load a txt file like so :


var getXMLHttpRequest = function()
{
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest();
}
else {
try {
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch(ex) {
return null;
}
}
};


var loadJSON = function(url)
{
var xmlHttp = getXMLHttpRequest();

if (xmlHttp != null)
{
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
JSON.parse(xmlHttp.responseText);
}
};


xmlHttp.send(null);

return xmlHttp.responseText;

}
else
alert("Your browser does not support XML HTTP.");
};





The content of the text file is a simple JSON object which loads fine in Firefox, but in IE i get an error pointing to line JSON.parse(xmlHttp.responseText);

Anyone know what's wrong?

Share this post


Link to post
Share on other sites
Looks like it was a comma in the json file, running it through JSON validator brought it up.

{
"name": "Black knight",

"images": {
"image1" : "assets/1.jpg",
"image2" : "assets/2.jpg",
"image3" : "assets/3.jpg",
"image4" : "assets/4.jpg",
}
}



The last comma was breaking things in IE.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this