Last active
January 6, 2016 02:29
-
-
Save ikuwow/9034c103768e75d37abc to your computer and use it in GitHub Desktop.
ピュアなJSでAPIリクエストをするメモ(jsonとjsonp) ref: http://qiita.com/ikuwow/items/ed5f3c9ee0bd6147b7f3
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(){ | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function(){ | |
if (this.readyState==4 && this.status==200) { | |
// responseをhogehogeする | |
} | |
}; | |
xhr.responseType = 'json'; | |
xhr.open('GET',endpoint,true); | |
xhr.send(); | |
})(); |
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(){ | |
var requestAjax = function(endpoint, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function(){ | |
if (this.readyState==4 && this.status==200) { | |
callback(this.response); | |
} | |
}; | |
xhr.responseType = 'json'; | |
xhr.open('GET',endpoint,true); | |
xhr.send(); | |
}; | |
})(); | |
requestAjax("http://example.com/endpoint1", function(response){ | |
// responseをhogehogeする | |
}); | |
requestAjax("http://example.com/endpoint2", function(response){ | |
// responseをhogehogeする | |
}); |
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(){ | |
var script = document.createElement('script'); | |
script.src = 'https://api.instagram.com/v1/users/5001435/media/recent/?access_token='+accessToken+'&callback=instaCallback'; | |
window.instaCallbackFavorites = function(response) { | |
// reponseをhogehogeする | |
}; | |
document.body.appendChild(script); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment