Skip to content

Instantly share code, notes, and snippets.

@tobyhede tobyhede/vsjsonp.js forked from juliocesar/vsjsonp.js
Last active Aug 29, 2015

Embed
What would you like to do?
// VSJONP ― Very Simple JSONP
// ==========================
//
// Usage:
// fetchJsonP({
// url: 'http://shit-no-cors.json',
// complete: function(response) {
// console.log(response);
// }
// });
var fetchJsonP = function(options) {
var options = options ? options : {},
script = document.createElement('script');
functionName = 'jsonp' + Math.floor(Math.random() * 9999);
window[functionName] = function(response) {
if (options.complete) options.complete(response);
}
script.src = options.url + "&callback=" + functionName;
script.onload = function() {
document.body.removeChild(script);
delete window[functionName];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.