I would make a jquery function that import a json value and return an array when we call it. I coded the following function but the returned array is empty.
The json file is very basic like this example :
{
"fruit": [ "babana", "pineapple", "apple" ],
"vegetable" : [ "salad", "carrot", "tomato" ]
}
I call my json with the following function
$( function() {
var fruit = new Array();
var vegetable = new Array();
var food = new Array();
function loadJson(result) {
$.getJSON('myfile.json', function (data) {
fruit = data.fruit;
vegetable = data.vegetable;
})
.error(function() {
console.log('error: JSON not loaded');
})
.done(function() {
//console.log( "JSON loaded!" );
var food = fruit.concat(vegetable);
return result;
});
}
After I call this function in another function with
loadJson(food); loadJson(fruit);
Can you help me?