Created
July 18, 2015 20:14
-
-
Save owebboy/1a096480cc6fd3316c54 to your computer and use it in GitHub Desktop.
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
// jsonp | |
function jsonp(url, callback) { | |
var callbackName = 'jsonp_callback_' + Math.round(100000 * Math.random()); | |
window[callbackName] = function(data) { | |
delete window[callbackName]; | |
document.body.removeChild(script); | |
callback(data); | |
}; | |
var script = document.createElement('script'); | |
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName; | |
document.body.appendChild(script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment