I need to create a javascript variable that acts the same as if I hard coded
var test = [{"first" : "second"}];
and so on. However I need to load the data from an external, local .json file and set that data equal to the variable. I've done TONS of different attempts such as
var test;
jQuery.ajax({
'async': false,
'global': false,
'url': "sequence.json",
'dataType': "json",
'success': function (data) {
test = data;
}
});
However in all cases, the original test variable is never set as if it were hard coded to a JSON object. Often, I'm unable to even set the value of test at all. What would be a good way to go about this?
successcallback and see if ajax call invokes it?testis null until the data loads. So if you'reconsole.loging it –– or running any code that depends on it –– prior tosuccessbeing called, you get null.