从事件回调之一内部调用 JQuery.ajax 或 JQuery.post 会导致来自 Moment.min.js 的类型错误 [英] Calling JQuery.ajax or JQuery.post from inside of one of the event callbacks results in a Type Error from Moment.min.js

查看:28
本文介绍了从事件回调之一内部调用 JQuery.ajax 或 JQuery.post 会导致来自 Moment.min.js 的类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 FullCalendar 制定时间表,但遇到了一些障碍.我正在尝试使用事件回调函数来创建一个新事件,并将新事件的信息发送到我的 php 脚本,然后将信息存储到服务器.但是每当我尝试从其中一个回调中调用 $.ajax 或 $.post 时(并且我已经尝试过其中的几个),我得到了这个:

I am working on a schedule using FullCalendar and i have hit a bit of a snag. I am trying to use the event callback functions to create a new event, and send the new event's information to my php script which then stores the information to the server. But whenever i try to call $.ajax or $.post from within one of the callbacks (and i have tried if from with in a few of them) i get this:

Uncaught TypeError: Cannot read property 'month' of undefined moment.js:684
extend.monthsShort moment.js:684
e jquery.min.js:4
Bc jquery.min.js:4
Bc jquery.min.js:4
Bc jquery.min.js:4
n.param jquery.min.js:4
n.extend.ajax jquery.min.js:4
$.fullCalendar.select advisorSchedule.js:141
Q fullcalendar.min.js:6
s fullcalendar.min.js:7
a fullcalendar.min.js:7
(anonymous function) fullcalendar.min.js:6
d jquery.min.js:3
n.event.dispatch jquery.min.js:3
r.handle

但是因为我使用的是 Moment.min.js,所以很难读懂问题出在哪里,所以我用 Moment.js 替换了 Moment.min.js,当错误再次出现时,我能够阅读问题所在:

But because i was using Moment.min.js it was kinda hard to read where the problem was coming from, so i replaces Moment.min.js with Moment.js, and when the error popped up again i was able to read where the problem was:

months : function (m) {
   return this._months[m.month()];
},

从我收集到的信息来看,在执行此函数时,m 尚未定义.这是我用来将新事件数据发布到 php 脚本的代码:

From what i gathered, m is undefined by the time this function is executed. Here is the code i used to post the new event data to the php script:

select:function(start, end, jsEvent, view){
        CURRENT_SELECTION_START = start;
        CURRENT_SELECTION_END   = end;

        console.log(CURRENT_SELECTION_START + '-' + CURRENT_SELECTION_END);

        $.ajax({

            url:'../AJAX/save_event.php',
            type: 'POST',
            data: {
                Start_Time: start,
                Event_Title: prompt('Title'),
                End_Time: end
            },

        });
    },

推荐答案

我假设 start 是一个矩对象.

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.

尝试 start.calendar()start.format("YYYY-MM-DD");(或类似的东西)而不是 start.

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

为我工作,希望也为你工作;)

worked for me, hopefully for you too ;)

帕特里克

这篇关于从事件回调之一内部调用 JQuery.ajax 或 JQuery.post 会导致来自 Moment.min.js 的类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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