title: How to return an array from jQuery ajax success function properly?
body: <p>TheObject = {</p>
  
  <pre><code>    getArray: function(){
          var groups = new Array;
          $.ajax({
                type: "POST",
                url: "link.php",
                success: function (data){
                    var counter = 0;
                    $('g',data).each(function(){    
                        var group_name = $(this).find("name").text();
                        var group_id = $(this).find("id").text();
                        var group = {
                           id: group_id,
                           name: group_name
                        }
                        groups[counter] = group;
                        counter++;
                    });
                    return groups;
                }
           });
       }
  
  }
  </code></pre>
  
  <p>And when I try to call this method:</p>
  
  <pre><code>var a = TheObject.getArray();
  alert(a);
  </code></pre>
  
  <p>It returns 'undefined'.
  I cant figure out where is the problem. The array gets created inside the success function but I'am unable to return it properly.
  Thanks for your help!</p>