Last active
August 29, 2015 14:05
-
-
Save otar/274f277f09bdf6a08562 to your computer and use it in GitHub Desktop.
Helper function for loading JSONP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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