title: Variables set during $.getJSON function only accessible within function
body: <p>This may be more of a scoping question. I'm trying to set a JSON object within a $.getJSON function, but I need to be able to use that object outside of the callback.</p>
  
  <pre><code>var jsonIssues = {};  // declare json variable
  
  $.getJSON("url", function(data) {
      jsonIssues = data.Issues;
  });
  
  // jsonIssues not accessible here
  </code></pre>
  
  <p>A similar question like this one was asked in another post, and the consensus was that anything I need to do with the JSON objects needs to be done within the callback function, and cannot be accessed anywhere else. Is there really no way that I can continue to access/manipulate that JSON object outside of the $.getJSON callback? What about returning the variable, or setting a global?</p>
  
  <p>I'd appreciate any help. This just doesn't seem right...</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Tried setting the $.ajax() async setting to false, and running through the same code, with no luck. Code I tried is below:</p>
  
  <pre><code>var jsonIssues = {};  // declare json variable
  
  $.ajax({ async: false });
  
  $.getJSON("url", function(data) {
      jsonIssues = data.Issues;
  });
  
  // jsonIssues still not accessible here
  </code></pre>
  
  <p>Also, I've had a couple responses that a global variable should work fine. I should clarify that all of this code is within <code>$(document).ready(function() {</code>. To set a global variable, should I just declare it before the document.ready? As such:</p>
  
  <pre><code>var jsonIssues = {};
  
  $(document).ready(function() {
  
    var jsonIssues = {};  // declare json variable
  
    $.getJSON("url", function(data) {
        jsonIssues = data.Issues;
    });
  
    // now accessible?
  }
  </code></pre>
  
  <p>I was under the impression that that a variable declared within document.ready should be "globally" accessible and modifiable within any part of document.ready, including subfunctions like the $.getJSON callback function. I may need to read up on javascript variable scoping, but there doesn't seem to be an easy to achieve what I'm going for. Thanks for all the responses.</p>
  
  <p><strong>UPDATE #2:</strong>
  Per comments given to answers below, I did use $.ajax <em>instead of</em> .getJSON, and achieved the results I wanted. Code is below:</p>
  
  <pre><code>var jsonIssues = {};
      $.ajax({
          url: "url",
          async: false,
          dataType: 'json',
          success: function(data) {
              jsonIssues = data.Issues;
          }
      });
  
      // jsonIssues accessible here -- good!!
  </code></pre>
  
  <p>Couple follow-up comments to my answers (and I appreciate them all). My purpose in doing this is to load a JSON object initially with a list of Issues that the user can then remove from, and save off. But this is done via subsequent interactions on the page, and I cannot foresee what the user will want to do with the JSON object <em>within</em> the callback. Hence the need to make it accessible once the callback complete. Does anyone see a flaw in my logic here? Seriously, because there may be something I'm not seeing...</p>
  
  <p>Also, I was reading through the .ajax() jQuery documentation, and it says that setting async to false "Loads data synchronously. Blocks the browser while the requests is active. It is better to block user interaction by other means when synchronization is necessary."</p>
  
  <p>Does anyone have an idea how I should be blocking user interaction while this is going on? Why is it such a concern? Thanks again for all the responses.</p>