title: jQuery.ajax() success callback store data to return
body: <p>I'm trying to get some data from a PHP script in a project right now. All examples I found searching for AJAX callback functions "use" the data already in the callback itself, but I want to fetch data and store it in a way ready to be returned.</p>
  
  <pre><code>function getEle (id) {
      var element = []; 
  
      $.ajax({
          url: 'slides.php',
          type: 'POST',
          data: {"id": id},
          success: function(data) {
              var content = data;
  
              element[0] = id;
              element[1] = content;
              // if I alert(element[1]); here it will work! 
  
  
  
          }
      });
      alert(element[1]); // here it just won't :/ ("undefined")
      return element;
  }
  </code></pre>
  
  <p>Somewhere in my script some function needs to <code>getEle(ments)</code> but all I get is <code>undefined</code>.
  is there a way to do what I want? Or is there maybe a better way to do this?</p>