如何使用日期范围选择器和ajax [英] How to use date range picker along with ajax

查看:88
本文介绍了如何使用日期范围选择器和ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用日期范围选择器javascript库从用户选择日期范围

I am using date range picker javascript library To select range of date from user

                  $('#date_range').daterangepicker({
                    arrows:true,
                    dateFormat: 'd-M-yy',
                    rangeSplitter: 'to',
                    datepickerOptions: {
                         changeMonth: true,
                         changeYear: true,
                         minDate: new Date("01/01/2011") //Account created date
                    },
                    closeOnSelect: true,
                    onChange: function(){
                                    //ajax call goes here

                                    }
                  });

在我的ajax通话中,我正在使用日期范围更新屏幕。但是这个on change函数运行两次,ajax返回旧的日期值。如果需要在日期范围选择器的更改功能上使用ajax功能。

In my ajax call i am updating the screen with date range. but this on change function runs two times and ajax returns old date value. If need to use ajax functionality with on change function of date range picker.

如果有任何人找到使用onchange功能的解决方案,请使用正确的日期和迄今为止,亲密的我请。在此先感谢

If any one find solution for using onchange function at once with correct from and to date, intimate me please. Thanks in Advance

推荐答案

我是这样做的:

$('#date_range').daterangepicker({
    "startDate": "01/01/2016",
    "endDate": "07/27/2016"
    }, function(start, end, label) {
        $.ajax({
            url:"/your_url",
            method: "GET", // or POST
            dataType: "json",
            data: {from: start.format('YYYY-MM-DD'), to: end.format('YYYY-MM-DD')},
            success:function(result) {
                console.log("sent back -> do whatever you want now");
            }
        });
    });

此函数的作用类似于 $(#date_range)。change(function (){}); ,但它也有一些参数。

This function works like $("#date_range").change(function(){});, but it has some parameters too.

您可能希望将日期字符串更改为您的有效日期收到它,如果你想做一些过滤。

You might want to change the date string to a valid date where you receive it, in case you want to do some filtering.

我在 http://www.daterangepicker.com/ ,请查看更多示例! :)

I found about this function on http://www.daterangepicker.com/, look there for more examples! :)

这篇关于如何使用日期范围选择器和ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆