I am trying to get an event calendar working from json data. I just want to highlight dates, and have a div update below the calendar with the event details when the user clicks
In order to get JSON data from another domain, you have to use JSONP with a callback function. The Github API supports this (example), and jQuery handles making the callback automatically with dataType: 'jsonp'
.
This is how I get JSON data from a Github gist with jQuery:
$.ajax({
url: 'https://api.github.com/gists/'+gistid,
type: 'GET',
dataType: 'jsonp'
}).success( function(gistdata) {
// This can be less complicated if you know the gist file name
var objects = [];
for (file in gistdata.data.files) {
if (gistdata.data.files.hasOwnProperty(file)) {
var o = JSON.parse(gistdata.data.files[file].content);
if (o) {
objects.push(o);
}
}
}
if (objects.length > 0) {
// DoSomethingWith(objects[0])
}
}).error( function(e) {
// ajax error
});
(jsFiddle)