how to use datepicker apply to send a get request

Solutions on MaxInterview for how to use datepicker apply to send a get request by the best coders in the world

showing results for - "how to use datepicker apply to send a get request"
Paul
27 May 2019
1             $(document).ready(function(){
2                $('.daterange-btn').daterangepicker(
3                    {
4                        ranges   : {
5                            'Today'       : [moment(), moment()],
6                            'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
7                            'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
8                            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
9                            'This Month'  : [moment().startOf('month'), moment().endOf('month')],
10                            'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
11                        },
12                        startDate: moment().subtract(29, 'days'),
13                        endDate  : moment(),
14                    },
15                    function (start, end) {
16                        $('.daterange-btn').find('span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
17                        handleFilterEvent(start,end);
18                    }
19                )
20                function handleFilterEvent(startDate = null,endDate = null){
21                    var url = "https://www.google.com"+'?';
22                    var startDate = startDate ? startDate.format('YYYY-MM-DD') : '';
23                    var endDate = endDate ? endDate.format('YYYY-MM-DD') : '';
24                    var params = {};
25                    if(startDate && endDate){
26                        params.start_date =  startDate;
27                        params.end_date =  endDate;
28                    }
29                    url+= jQuery.param( params );
30                    location.href = url;
31                }
32            });