Fullcalendar event source not loading on first page load

Fullcalendar event source not loading on first page load

Hello all,

I am trying to figure out when I load a page with fullcalendar on it the event source that I want to display in month view is not being loaded. I have to click on the Week view then back on the month view and the display I want appears then. I will post snippets of code to illustrate what I have done:

  1. $(document).ready(function() {
  2.       
  3.       $('#calendar').fullCalendar({
  4.   header:{
  5. right: 'prev,next today',
  6. center: 'title',
  7. left: 'month, agendaWeek, resourceDay'
  8.   },
  9. minTime: '6:00am',
  10. maxTime: '8:00pm',
  11. events: '/json-events.php',
  12. resources:'./json-resources.php',
  13.                   
  14.                viewDisplay: function (view) {
  15. if (lastView == undefined) {
  16. lastView = 'firstRun';
  17. }
  18. //alert("viewname: "+ view.name + "lastView: " + lastView);
  19. if (view.name != lastView) {
  20. if(view.name == "month") {
  21. // alert("month");
  22. $("#calendar").fullCalendar("removeEventSource","/json-events.php");
  23. $("#calendar").fullCalendar("addEventSource", "/json-test.php");
  24. $("#calendar").fullCalendar("removeEventSource","/json-events.php");
  25. // $("#calendar").fullCalendar("rerenderEvent");
  26. // alert("add current event");
  27. // $("#calendar").fullCalendar("removeEventSource", "/json-events.php");
  28. // alert("remove current event");
  29. // $("#calendar").fullCalendar("removeEventSource", "/json-test.php");
  30. // alert("remove added event");
  31. }
  32. if (view.name == "agendaWeek") {
  33. // alert("in month: Delete litesource");
  34. $("#calendar").fullCalendar("addEventSource", "/json-events.php");
  35. $("#calendar").fullCalendar("removeEventSource", "/json-test.php");
  36. $("#calendar").fullCalendar("removeEventSource", "/json-events.php");
  37. }
  38. if (view.name == "resourceDay") {
  39. // alert("in day: add litesource");
  40. $("#calendar").fullCalendar("addEventSource", "/json-events.php");
  41. $("#calendar").fullCalendar("removeEventSource", "/json-test.php");
  42. $("#calendar").fullCalendar("removeEventSource", "/json-events.php");
  43. }
  44. lastView = view.name;
  45. }
  46. // alert("Done");
  47. }
  48.       });
  49. });
The above code works as I want it to once I click through the views. Initially when I load the page with fullcalendar on it, it displays the month view and a list of events on a given day. I have included a few pictures of what is happening as well. 

On initial page load: 

After clicking week then back to month: 


Thanks to whoever helps out.