XMLHttpRequest Synchronous or Asynchronous
<p>In my JS I am sending a get request to the bit.ly api to shorted a URL. The problem is I need the URL returned for use in the code.</p>

<p>Would it be best to use a synchronous request for this? As it stands any code after the XHR request that uses the bit.ly would fail because the response has not yet returned the short URL.</p>

<pre><code>bitlyXHR.onreadystatechange = function() {
    if (bitlyXHR.readyState == 4) {
        if (bitlyXHR.status == 200) {
            var obj = JSON.parse(bitlyXHR.responseText);
            // Do something
        }
    }
};

bitlyXHR.open("GET", "http://api.bitly.com/v3/shorten?login=&amp;apiKey=&amp;longUrl=" + longURL + "&amp;format=json");
bitlyXHR.send();

// Some code here that uses the short URL
</code></pre>
