Skip to content

Instantly share code, notes, and snippets.

@mrdoob
Created January 28, 2012 16:56
Show Gist options
  • Save mrdoob/1695006 to your computer and use it in GitHub Desktop.
Save mrdoob/1695006 to your computer and use it in GitHub Desktop.
JSONP
function getJSONP( url, callback ) {
var ud = 'json' + ( Math.random() * 100 ).toString().replace( /\./g, '' );
window[ ud ]= function ( o ) { callback && callback( o ); };
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = url.replace( 'callback=?','callback=' + ud );
document.body.appendChild( script );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment