Last active
November 28, 2015 17:58
-
-
Save fguisso/6a7cd2e2b41686b05cd7 to your computer and use it in GitHub Desktop.
JSONP with APIRest
This file contains 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
// The callback funciton | |
function yourFunction (data) { | |
//console.log(data); | |
} | |
// create <script> | |
var myScript = document.createElement('SCRIPT'); | |
// set the src URL with ?callback=yourFunction | |
myScript.src = 'http://example.com/api/user?callback=yourFunction'; | |
// get the <head> | |
var head = document.getElementsByTagName('head')[0]; | |
// insert your <script> before <head> | |
head.insertBefore(myScript, head.childNodes[0]); | |
// For test, change the url http://swapi.co/api/people/1/ (Star Wars API) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment