日期范围选择器使用AJAX发送选定日期

时间:2022-09-26 11:05:39

Date range picker.

日期范围选择器。

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

我试图用Ajax发送选定的日期,但我收到错误:

  $(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:

出于某种原因,我收到此错误:

日期范围选择器使用AJAX发送选定日期

1 个解决方案

#1


2  

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:

start是一个时刻对象,你的PHP代码期望的是一个字符串。我不确定在序列化对象时为什么会给你这个错误,但也许你自己将它转换为字符串会修复它:

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

#1


2  

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:

start是一个时刻对象,你的PHP代码期望的是一个字符串。我不确定在序列化对象时为什么会给你这个错误,但也许你自己将它转换为字符串会修复它:

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