0

I am having issues getting the results returned through ajax call. The console.log(data) is returning [undefined] on this ajax call:

$.get(root+'hoteles/functions/ean/get-zones.php', { zo: zones_arr }, function(data){ 
     return data; 
     },'json');

The response from the file is returning correctly and is json encoded including the header tag.

lov2code
  • 394
  • 1
  • 6
  • 19

2 Answers2

0

After trying everything I googled, I thought that possibly the response was not done loading. So I added an addition and it worked like a charm! Similar to the issue of complete and success on $.ajax call.

I simply added .done() after the function returned the data, and it finally did what it was meant to do!

$.get(root+'hoteles/functions/ean/get-zones.php',{ zo: zones_arr }, function(data){

   },'json').done(function(data){
         console.log('It worked!');
         console.log(data);
         return data;
   }); 

If anyone has a better solution please post so others can figure this out too!

lov2code
  • 394
  • 1
  • 6
  • 19
0

If anyone has a better solution please post so others can figure this out too!

Well you can do that at the success callback too:

$.get(root+'hoteles/functions/ean/get-zones.php',{ zo: zones_arr }, function(data){
     console.log('It worked!');
     console.log(data);
},'json');

You don't need to have a return statement there.

Jai
  • 74,255
  • 12
  • 74
  • 103