Skip to content

Instantly share code, notes, and snippets.

@otar
Last active August 29, 2015 14:05
Show Gist options
  • Save otar/274f277f09bdf6a08562 to your computer and use it in GitHub Desktop.
Save otar/274f277f09bdf6a08562 to your computer and use it in GitHub Desktop.
Helper function for loading JSONP
var jsonp = function(url)
{
var script = window.document.createElement('script');
script.async = true;
script.src = url;
script.onerror = function()
{
alert('Can not access JSONP file.')
};
var done = false;
script.onload = script.onreadystatechange = function()
{
if (!done && (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete'))
{
done = true;
script.onload = script.onreadystatechange = null;
if (script.parentNode)
{
return script.parentNode.removeChild(script);
}
}
};
window.document.getElementsByTagName('head')[0].appendChild(script);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment