Last active
December 1, 2015 01:00
-
-
Save data-doge/4411f3bd46538682b9e6 to your computer and use it in GitHub Desktop.
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
// 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. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$.ajax
docs http://api.jquery.com/jquery.ajax/