i have this javascript code for accessing a JSON. There is a variable v1 that i declared global, but i can't access it outside this function.
$.ajax({
type: 'GET',
url: url,
async: true,
jsonpCallback: 'jsonCallback',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
//console.log("good");
v1 = [];
$.each(json, function(key, val) {
// $('ul').append('<li id="' + key + '">' + val.dir + ' ' + val.nr + '</li>');
if(val.dir === "IESIRE"){
// console.log(val.data);
v1.push(val.data);
}
});
},
error: function(e) {
console.log(e.message);
}
});
console.log(v1);
Please help to understand this.