Answers for "how to use datepicker apply to send a get request"

0

how to use datepicker apply to send a get request

$(document).ready(function(){
                $('.daterange-btn').daterangepicker(
                    {
                        ranges   : {
                            'Today'       : [moment(), moment()],
                            'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                            'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
                            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                            'This Month'  : [moment().startOf('month'), moment().endOf('month')],
                            'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                        },
                        startDate: moment().subtract(29, 'days'),
                        endDate  : moment(),
                    },
                    function (start, end) {
                        $('.daterange-btn').find('span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
                        handleFilterEvent(start,end);
                    }
                )
                function handleFilterEvent(startDate = null,endDate = null){
                    var url = "https://www.google.com"+'?';
                    var startDate = startDate ? startDate.format('YYYY-MM-DD') : '';
                    var endDate = endDate ? endDate.format('YYYY-MM-DD') : '';
                    var params = {};
                    if(startDate && endDate){
                        params.start_date =  startDate;
                        params.end_date =  endDate;
                    }
                    url+= jQuery.param( params );
                    location.href = url;
                }
            });
Posted by: Guest on August-14-2020

Code answers related to "how to use datepicker apply to send a get request"

Code answers related to "Javascript"

Browse Popular Code Answers by Language