lokesh lokesh - 2 months ago 18
Java Question

Events not inserting in to Bootstrap calendar

my code is

events: function(callback) {
$.ajax({
url: 'schoolmanagement/jsonevents',
dataType: "json" ,
success: function(doc) {
var events = [];
$(doc).find('el').each(function() {
events.push({
title: $(this).attr('title'),
start: new Date($(this).attr('start')),
end: new Date($(this).attr('end')),
allDay: true,
className: 'bgm-cyan',// will be parsed
});
});
callback(events);
}
});
},


and my json response is

{"el": [
{"end":"2016-09-25T00:00:00","start":"2016-09-25T00:00:00","title":"Weekly Holiday"},
{"end":"2016-10-02T00:00:00","start":"2016-10-02T00:00:00","title":"Gandhi Jayanti"},
{"end":"2016-10-09T00:00:00","start":"2016-10-09T00:00:00","title":"Weekly Holiday"},
{"end":"2016-09-15T00:00:00","start":"2016-09-15T00:00:00","title":"School Foundation day"}
]}

Answer

You are returning json not html/xml use the following:

success: function(doc) {
  var events = [];
 $.each( doc.el,function(i,v) {
    events.push({
      title: v.title,
      start: v.start,
      end: v.end,
      allDay: true,
      className: 'bgm-cyan', // will be parsed
    });
  });
  callback(events);
}