Skip to content

Instantly share code, notes, and snippets.

@twolfe2
Last active June 3, 2016 16:43
Show Gist options
  • Save twolfe2/8b4970b384083155ba03898bf559f21f to your computer and use it in GitHub Desktop.
Save twolfe2/8b4970b384083155ba03898bf559f21f to your computer and use it in GitHub Desktop.
//when the button on the page is clicked the ajax request will be made
$('button').click(function(event){
event.preventDefault(); //prevents browsers default behavior
//make the ajax request
$.ajax({
url: https:'//api.github.com/users/twolfe2', //url could be first parameter to $.ajax instead
data: {
format: 'json'//tells github we want our data in json format
},
error: function (){
alert("An error occured");
},
dataType: 'jsonp',//JSONP allows us to make a cross-domain request
success: function(response) {
alert("GitHub User:" + response.login + "is located in" + response.location);
},
type: 'GET' //GET is the default
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment