Daterange picker posting data with ajax

I have added Script for selecting date and on click of apply button i want to call an ajax to get the data. But it is not working. When the code reach to the ajax it stops and in console i got this error.

I am sending data as POST but in my controller i just received the token. and date range is not passed to the controller.

TypeError: e is undefined

My code is as below.

$('.search_dashboard_data').daterangepicker({
            autoUpdateInput: false,
            locale: {
                cancelLabel: 'Clear'
            }
        });

        function ajaxCallForSearchedData(searched_date)
        {
            //console.log(searched_date);
            $.ajax({
                type: 'POST',
                url: '{{ route('agent.get_searched_dashboard_data') }}',
                data: {
                    'date_range': searched_date,
                    "_token": "{{ csrf_token() }}",
                },
                success: function (result) {
                    console.log('result' + result);
                    $('#all_fees_data').hide();
                    $('#searched_fees_data').html(result);
                    $('#all_time').hide();
                    $('#day').hide();
                    $('#week').hide();
                    $('#month').hide();
                    $('#searched_fees_data').show();
                }
            });
        }

        $('.search_dashboard_data').on('apply.daterangepicker', function(ev, picker) {
            /*$(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));*/
            /*alert($(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY')));*/

            var searched_date = $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));
            ajaxCallForSearchedData(searched_date);
        });

1 answer

  • answered 2019-09-12 05:26 Sabeer C A

    Try to use like :

        $('.search_dashboard_data').daterangepicker({
            autoUpdateInput: false,
            locale: {
                cancelLabel: 'Clear'
            }
        }, cb);
    
        function ajaxCallForSearchedData(searched_date)
        {
            //console.log(searched_date);
            $.ajax({
                type: 'POST',
                url: '{{ route('agent.get_searched_dashboard_data') }}',
                data: {
                    'date_range': searched_date,
                    "_token": "{{ csrf_token() }}",
                },
                success: function (result) {
                    console.log('result' + result);
                    $('#all_fees_data').hide();
                    $('#searched_fees_data').html(result);
                    $('#all_time').hide();
                    $('#day').hide();
                    $('#week').hide();
                    $('#month').hide();
                    $('#searched_fees_data').show();
                }
            });
        }
    
        function cb(start, end) {
            var searched_date =  start.format('MM/DD/YYYY') + ' - ' + end.format('MM/DD/YYYY');
            ajaxCallForSearchedData(searched_date);
        }