Search code examples
jqueryajaxdatepickerjquery-ui-datepickerfosjsroutingbundle

Ajax call in datepicker with selected date jQuery?


I am building Monthpicker. How to make ajax call inside datepicker?

$(function () {
    $('#datepicker').datepicker({
        minDate: new Date('2013'),
        maxDate: new Date(),
        changeMonth: true,
        changeYear: true,
        dateFormat: "yy-mm",
        onClose: function () {
            $.ajax({
                url: Routing.generate('ajax_table', $this)
            })
        }
    });
}); 

How to pass selected values in onClose? I want to render a table after ajax call. I am using fos_routing.js.


Solution

  • You can write something like this:

    $(function () {
        $('#datepicker').datepicker({
            minDate: new Date('2013'),
            maxDate: new Date(),
            changeMonth: true,
            changeYear: true,
            dateFormat: "yy-mm",
            onClose: function (selectedDate) {
                $.ajax({
                    url: Routing.generate('ajax_table', {selectedDate: selectedDate})
                })
            }
        });
    });