简体   繁体   中英

Date range picker send selected date with AJAX

Date range picker.

I am trying to send selected date with Ajax, but I get error:

  $(function() {
    $('input[name="daterange"]').daterangepicker({
      singleDatePicker: true,
      startDate: moment(),
        showDropdowns: true
      },
      function(start,end, label) {

        $.ajax({
            url: 'process.php',
            type: 'POST',
            data: {"date": start},
            dataType: 'html',
            method: 'post',
            success: function(data) {
              alert(data);
            }
        })
    });
  });

For some reason I get this error:

在此处输入图片说明

start is a moment object and what your PHP code expects is a string. I'm not sure why moment is giving you that error when serializing the object, but perhaps converting it to a string yourself will fix it:

var date_as_string = start.format('YYYY-MM-DD')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM