Ajax call in datepicker with selected date jQuery?

2.2k Views Asked by At

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.

2

There are 2 best solutions below

1
Kevin Bui On BEST ANSWER

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})
            })
        }
    });
}); 
0
Mohanlal Prajapati On

According to http://api.jqueryui.com/datepicker/#option-onClose, Jquery UI DatePicker onClose event has 2 arguments. dateText and datepicker Instance.

You can use dateText for your ajax call. I hope this will help.