I am setting a variable within the
$.getJSON("filename.json", function(data){ ... });
method, and printing the variable immediately after calling this function. The console then tells me that my variable does not exist. Why is this happening and how can I resolve it?
Bugged Code:
function
$.getJSON("dimple1.json", function(data){
var data1 = data;
console.log(data1);
});
console.log(data1); //gives: "ReferenceError: data1 is not defined"
}
console output:
[14:40:46.044] Unknown property 'box-sizing'. Declaration dropped.
[14:40:46.049] ReferenceError: data1 is not defined
[14:40:46.103] not well-formed
[14:40:46.104] ({information:[{month:"January", 'Unit Sales':"18000"}, {month:"February", 'Unit Sales':"6000"}, {month:"March", 'Unit Sales':"20000"}, {month:"April", 'Unit Sales':"35000"}, {month:"May", 'Unit Sales':"13000"}, {month:"June", 'Unit Sales':"4000"}, {month:"July", 'Unit Sales':"6000"}, {month:"August", 'Unit Sales':"9500"}, {month:"September", 'Unit Sales':"28000"}, {month:"October", 'Unit Sales':"21000"}, {month:"November", 'Unit Sales':"10000"}, {month:"December", 'Unit Sales':"6000"}]})