I am trying to load a .json file into a variable in javascript, but I cannot get it to work. This is probably a small mistake, but I can not find it.
Everything works fine when I use static data as follows:
var json = { id: "whatever", name: "start", children: [{ "id":"0.9685","name":" contents:queue"},{ "id":"0.79281","name":" contents:mqq_error"}}] }
So I put everything in {} in the content.json file and tried to load it into a local javascript variable as described here: load json into a variable
var json = (function() { var json = null; $.ajax({ 'async': false, 'global': false, 'url': "/content.json", 'dataType': "json", 'success': function (data) { json = data; } }); return json; })();
I ran it with a chrome debugger, and it always tells me that the value of the json variable is null. Content.json is in the same directory as the .js file that calls it.
What did I miss?
json javascript jquery
PogoMips Jan 23 '13 at 16:34 2013-01-23 16:34
source share