My experience with Drupal and Ajax has been limited to the context of a form. In this case, there is no form involved, so also no pre-process.
I am using FullCalendar. My desired flow is this:
- Prior to rendering the calendar from js, or re-rendering it when the month is changed, call a controller method
- The controller methods create an array of dates for the requested month that are holidays or reservations
- The date array is then returned to js to be iterated and used make a FullCalendar api call to set the attributes/content of the given date
The problem I am having is that all mentions of AJAX I find are related to returning markup to replace page markup. In particular, I have two issues:
-
How do I return the array from the AJAX method in the controller? A response object has to be a string
-
How do I act on the returned data? I can’t just do
var myDates = $.ajax()
I can process it in the AJAX success function, but that function is outside the FullCalendar object that does the setup and rendering, meaning I think that I need to get that array back inside the FullCalendar object that called the AJAX rather than operating on it in the AJAX success method.