So I’m a little new at this, a the code I have so far is not working yet, but if anyone can tell me what i missing I would be grateful.
Basically, I’m trying to make a call to github’s api, which returns json data. I’d eventually like to parse it and display only specific information, but at the present I’m just trying to get the data to show in my browser. Here is what I have so far:
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: "https://api.github.com/repos/VonC/gitolite/git/refs/tags",
dataType: "jsonp", // I'm under the impression i should use jsonp, since this is a cross domain call
success: function (returndata)
{
$('.result').html(returndata);
alert('Load was performed.');
}
});
});
</script>
The url definitely works: when you call it using CURL, the following json data is returned:
[
{
"object": {
"type": "commit",
"sha": "9accde83842523e18de320fc2f0a8efeaebef27b",
"url": "https://api.github.com/repos/jeffreycwitt/jeffswebpage/git/commits/9accde83842523e18de320fc2f0a8efeaebef27b"
},
"url": "https://api.github.com/repos/jeffreycwitt/jeffswebpage/git/refs/heads/master",
"ref": "refs/heads/master"
}
]
Thanks for any advice you can give me.
dataTypeshould probably bejsonpand notjasonp. Even better, it should simply bejsonas you are not making a JSONP call.Another thing you should watch out for is that
returndatais going to be the actual, parsed JavaScript object that comes out of the JSON representation, not the JSON object as a string. This means that you cannot put it straight into the.resultdiv.The following seems to work for me: