Created
March 17, 2016 09:29
-
-
Save hyamamoto/d62b1ac86fb5bc995a03 to your computer and use it in GitHub Desktop.
Legacy JSONP request maker. (Tested on > IE7, > Chrome21, > Firefox 17)
This file contains hidden or 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
var $jsonp = (function () { | |
var that = {}; | |
that.send = function (src, options) { | |
var options = options || {}, | |
callback_name = options.callbackName || 'callback', | |
on_success = options.onSuccess || function () { | |
}, | |
on_timeout = options.onTimeout || function () { | |
}, | |
timeout = options.timeout || 10; | |
var timeout_trigger = window.setTimeout(function () { | |
window[callback_name] = function () { | |
}; | |
on_timeout(); | |
}, timeout * 1000); | |
window[callback_name] = function (data) { | |
window.clearTimeout(timeout_trigger); | |
on_success(data); | |
}; | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.async = true; | |
script.src = src; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
}; | |
return that; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment