0

I am getting some data from a server using $.getJSON as follows ..

$.getJSON( 'http://192.168.2.24/index.php/hooks/' + a[i].BSSID, function() {
  console.log( "success" );
})
  .done(function(data) {
    url_redirect = data.SSID;
    console.log("DATA:" + url_redirect)
  }) ...

Before all of this I declare the variable url_redirect but this is not set with url_redirect = data.SSID even though the console.log proves it is. If I set var url_redirect = ""; right at the beginning of my script does this not make it global?

maxum
  • 2,825
  • 4
  • 33
  • 49
  • to make it global, you have to declare it outside any function. – ADreNaLiNe-DJ Jul 06 '16 at 09:48
  • it is the first line in my script outside of any function – maxum Jul 06 '16 at 09:49
  • @ADreNaLiNe-DJ — Only in strict mode, which doesn't appear to be being used here. (Although it should be, strict mode is best practise) – Quentin Jul 06 '16 at 09:50
  • 1
    So, it is global, but ajax is asynchronous. So, if you read the variable after you ajax call, it's normal taht you don't have the result => tha jaxa call is not `done`. – ADreNaLiNe-DJ Jul 06 '16 at 09:50

0 Answers0