Skip to content

Instantly share code, notes, and snippets.

@data-doge
Last active December 1, 2015 01:00
Show Gist options
  • Save data-doge/4411f3bd46538682b9e6 to your computer and use it in GitHub Desktop.
Save data-doge/4411f3bd46538682b9e6 to your computer and use it in GitHub Desktop.
// assuming you've included jQuery
$.ajax({
method: 'GET',
url: 'https://remote-server.com/path/to/resource.json'
}).done(function (res) {
console.log('res: ', res) // can view the server response here
}).fail(function (err) {
console.log('request unsuccessful')
})
// if you need to send additional parameters with your request
$.ajax({
method: 'GET',
url: 'https://remote-server.com/path/to/resource.json',
data: {
param1: 'something',
param2: 'something else'
}
}).done(function (res) {
console.log('res: ', res) // can view the server response here
}).fail(function (err) {
console.log('request unsuccessful')
})
// example request to http://pokeapi.co/api/v1/pokemon/1
$.ajax({
method: 'GET',
url: 'http://pokeapi.co/api/v1/pokemon/1'
}).done(function (res) {
console.log('res: ', res) // can view the server response here
}).fail(function (err) {
console.log('request unsuccessful')
})
// the above request prints the following to the console (http://imgur.com/z4m7hwd)
// that's your response object. you can do whatever you want with it.
@data-doge
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment