how to use datepicker apply to send a get request code example
Example: 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;
}
});