title: Return ajax variable with external URL
body: <p>I'm trying to figure out why I can't get the variable value from an ajax request. Here is my code:</p>
  
  <pre><code>country_locator = function() {
      var country_iso;
  
      $.getJSON("https://api.wipmania.com/jsonp?callback=?", "", function(json) {
          country_iso = json.address.country_code;
      });
  
      return country_iso;
  }
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>$.ajax({
          url: "https://api.wipmania.com/jsonp?callback=?",
          async: false,
          dataType: "json",
          success: function(data) {
              country_iso = data.address.country_code;
          }
      });
  </code></pre>
  
  <p>and</p>
  
  <pre><code>var country_iso;
  country_locator = function() {
      $.getJSON("https://api.wipmania.com/jsonp?callback=?", "", function(json) {
          country_iso = json.address.country_code;
      }).success/complete(function() {
          return country_iso;
      });
  }
  </code></pre>
  
  <p>but with <code>alert(country_locator());</code> I get an undefined variable error.</p>
  
  <p>I have found this link: <a href="https://stackoverflow.com/questions/6443115/get-the-variable-of-a-json-request-outside-the-function-jquery">Get the variable of a json request outside the function (jquery)</a> but didn't manage to get it work.</p>