I am trying to call a variable outside of .getJSON function. I am declaring it outside of the .getJSON function, then assigning it a value inside the .getJSON function. However, when I try to pull it out after, it says it is empty (when I can see in the console log that it has the information inside). Here's the code:
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var waypts = [];
$.getJSON("/westcoast_map.php", // The server URL
{ westcoast_id : $('.opener').data('westcoast_id') }, // Data you want to pass to the server.
function(json) {
waypts = json[1];
console.log(waypts); //prints out full array
});
console.log(waypts); //prints out an empty array