Skip to content

Instantly share code, notes, and snippets.

@BlaM
Created August 2, 2018 15:17
Show Gist options
  • Save BlaM/b271efe2085d7a713fdc010792e6ed70 to your computer and use it in GitHub Desktop.
Save BlaM/b271efe2085d7a713fdc010792e6ed70 to your computer and use it in GitHub Desktop.
function jsonp(u,d,cb){
var rndKey = 'c' + Math.round(Date.now()) + '_' + jsonp.length;
jsonp.cb[rndKey] = function(data) {
cb(data);
}
d.callback = 'jsonp.cb.' + rndKey;
var p = [];
for (var e in d) {
if (d.hasOwnProperty(e)) {
p.push(encodeURIComponent(e) + '=' + encodeURIComponent(d[e]));
}
}
var s = document.createElement('SCRIPT');
s.src = u + (u.indexOf('?') > 0 ? '&' : '?') + p.join('&');
document.body.appendChild(s);
}
jsonp.cb = {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment