title: AJAX call within Javascript class (prototype function)
body: <p>I am implementing a Javascript class which I am having trouble getting to work.
  After I initialize an instance of the class, I then call a method of that class which makes an AJAX request. The data that is returned on 'success' of the AJAX function is then needed to be set to the a property of that instance. When I output the this.results variable later in my code, it is empty when it shouldn't be. Here is my code:</p>
  
  <pre><code>//Individual Member Class
  function GetReports(options) {  
      this.options = options;
      this.results = {};
  }
  
  GetReports.prototype.getResults = function() {
      jQuery.ajax({
          type      :  'post',
          dataType  :  'json',
          url       :  'reporting/getStaffMemberReports',
          async     :  false,
          data      :  options,
          success   :  function(data) {
              this.results = data;
              setResult(this.results);
          }
      }); 
  }
  
  GetReports.prototype.returnResults = function(type) {   
      if(type === "JSON") {       
          JSON.stringify(this.results);
      } else if (type === "serialize") {
          this.results.serialize();
      }
  return this.results;
  };
  
  GetReports.prototype.setResult = function(data) {
      this.results = data;
  };
  </code></pre>
  
  <p>And my code which creates an instance of the 'class':</p>
  
  <pre><code>var jsonString = &lt;?php echo json_encode($JSONallocatedStaffMembers); ?&gt;;
      options = {
          all     : true,
          members : JSON.parse(jsonString),
          type    : 'highperform'
      };
      var all = new GetReports(options);
      all.getResults();
      var results = all.returnResults("JSON");
      console.log(results);
  </code></pre>
  
  <p>Now, as the AJAX call is asynchronous, I was thinking this may be the issue? I have tried putting 'async     :  false,' in but that doesn't help. 
  Can anyone see where I am going wrong?</p>