Created
October 21, 2016 11:43
-
-
Save SamirTalwar/44ad42f030bf98cdee8be6c5c91c39aa to your computer and use it in GitHub Desktop.
A quickly-implemented, barely-tested JSONP client implementation, without jQuery.
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
| function getJSONP(address, callback) { | |
| const random = Math.floor(Math.random() * 65536) | |
| const callbackName = 'getJSONP_callback_' + random | |
| window[callbackName] = function() { | |
| document.body.removeChild(script) | |
| delete window[callbackName] | |
| callback.apply(null, arguments) | |
| } | |
| const script = document.createElement('script') | |
| script.src = address.replace('${callback}', callbackName) | |
| document.body.appendChild(script) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment