【问题标题】:Daterange picker posting data with ajax使用 ajax 发布数据的日期范围选择器
【发布时间】:2019-09-12 03:54:24
【问题描述】:

我添加了用于选择日期的脚本,并在单击应用按钮时我想调用一个 ajax 来获取数据。但它不起作用。当代码到达 ajax 时它会停止并且在控制台中我得到了这个错误。

我将数据作为 POST 发送,但在我的控制器中我刚刚收到了令牌。并且日期范围未传递给控制器​​。

TypeError: e is undefined

我的代码如下。

$('.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);
        });

【问题讨论】:

  • 这个函数在哪里调用 ajaxCallForSearchedData(searched_date)

标签: jquery laravel daterangepicker


【解决方案1】:

尝试使用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);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多