Calling JQuery.ajax or JQuery.post from inside of one of the event callbacks results in a Type Error from Moment.min.js

五迷三道 提交于 2019-11-28 12:09:27

I assume start is a moment-object.

I had the same problem and it seems: you can't send the moment-object, so you need to get the value as an integer or something else.

Try start.calendar() or start.format("YYYY-MM-DD"); (or something similar) instead of start.

worked for me, hopefully for you too ;)

Patrick

I just had this exact same problem (it's how I came across this post).

To send the whole object you need to stringify it.

var now = moment();

$.ajax({
      url: 'http://example.com',
      contentType: 'application/json',
      data: JSON.stringify(now),
      type: 'POST'
});

Don't send start and end directly as the parameters to the AJAX request.

var startDate = start.format('YYYY-MM-DD'),
    endDate = end.format('YYYY-MM-DD'),
    params = {'from':startDate, 'to':endDate};
$.ajax({
      url: 'http://example.com',
      contentType: 'application/json',
      data: params,
      type: 'POST'
    }).done(function(data) {
        console.log('Successful! ', data);
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!