Last active
August 29, 2015 13:56
-
-
Save JosePedroDias/8928193 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
window.jsonpCbs = {}; | |
var jsonp = function(uri, cb) { | |
var key = 'cb' + Math.floor( Math.random() * 100000 ); | |
var cb2 = function() { | |
delete window.jsonpCbs[key]; | |
cb.apply(null, arguments); | |
}; | |
window.jsonpCbs[key] = cb2; | |
var scriptEl = document.createElement('script'); | |
scriptEl.setAttribute('type', 'text/javascript'); | |
var sep = (uri.indexOf('?') === -1) ? '?' : '&'; | |
scriptEl.setAttribute('src', [uri, sep, 'jsonp=jsonpCbs.', key].join('')); | |
document.head.appendChild(scriptEl); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment