title: Placing an ajax json object into a javascript variable
body: <p>I've been trying to figure this one out since <a href="https://stackoverflow.com/questions/27606901/getting-jira-fixversion-json-list-with-an-ajax-call-and-authorisation">my earlier question</a>.</p>
  
  <p>I can receive the data, as I see it under resources using <code>Develop &gt; Show Web Inspector</code> on safari. But I can't seem to assign it successfully to a variable to use later on. </p>
  
  <pre><code>&lt;script&gt;
  function getData () {
    $.ajax
      ({
        type: "GET",
        url: "https://myjirasite.com/jira/rest/api/2/project/ON/versions?",
        dataType: 'jsonp',
        //async: true,
           beforeSend: function (xhr) {xhr.setRequestHeader('Authorization', make_base_auth("myusername", "mypassword"));},
        success: function (){
  
        //Attempt 1 at outputting the result to an alert. 
        alert(JSON.parse(data));            
        }
      });
  
    }
  
  
  function make_base_auth(user, password) {
    var tok = user + ':' + password;
    var hash = btoa(tok);
    return 'Basic ' + hash;
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>In a second attempt I assign the ajax call to a variable and attempt to print that out to an alert. No success. the alert is empty</p>
  
  <pre><code>  var jqXHR = $.ajax
      ({
        type: "GET",
        url: "https://myjirasite/jira/rest/api/2/project/ON/versions?",
        dataType: 'jsonp',
        async: false,
           beforeSend: function (xhr) {xhr.setRequestHeader('Authorization', make_base_auth("myusername", "mypassword"));},
        success: function (data){
          alert(JSON.parse(data));            
        }
      });
  
      alert(JSON.parse(jqXHR.responseText));
  </code></pre>
  
  <p>I know that the issue lies with ajax calls being asynchronous, but I can't figure out how to write the callback such that I can get the json data into a variable to use later in via a different function. </p>