Skip to content

Instantly share code, notes, and snippets.

@gwuhaolin
Created March 25, 2015 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwuhaolin/c1a7a1269d44963e437f to your computer and use it in GitHub Desktop.
Save gwuhaolin/c1a7a1269d44963e437f to your computer and use it in GitHub Desktop.
mini jsonp
function jsonp(url, callback) {
var script = document.createElement('script');
script.type = "text/javascript";
script.src = url + (url.indexOf('?') > 0 ? '&' : '?') + 'callback=CB&' + Date.now();
script.onload=function(){
script.parentNode.removeChild(script);
};
window['CB'] = function (json) {
callback(json);
};
document.head.appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment