0

I'm trying to access a variable outside of my jquery .get request, but it keeps saying 'undefined'.

The code I'm using is as follows:

var userlat;
$.get("/ajax/getInitCoords", {}, function(data) {
    userlat = data.lat;
});
console.log(userlat);

If I move the console log part inside the brackets it works fine, but I need to access it outside that.

rgettman
  • 176,041
  • 30
  • 275
  • 357
BigJobbies
  • 499
  • 8
  • 20

0 Answers0