I am using FullCalendar and attempting to update an event start time when a user drags and drops an event in my calendar. This is the code I am using attached to the eventDrop callback (https://fullcalendar.io/docs/eventDrop):
alert(info.event.id + ' was dropped on ' + info.event.start);
$.ajax({
url: '/Post/dropPost',
type: 'POST',
data: { 'postSchedule': info.event.start, 'postId' : info.event.id },
});
},
只要警报显示正确的事件ID和正确的开始日期(采用以下格式:Tue May 05 2020 04:36:00),它就可以发挥作用。还调用'/ Post / dropPost'方法,并且可以正确传递postId变量。
但是,当它更新我的数据库时,postSchedule始终更新为“ 00:00:00 00:00:00”。
这是我的dropPost方法:
public function dropPost()
{
$data=[];
$postSchedule = $_POST['postSchedule'];
$postId = $_POST['postId'];
$droppedPost = new PostModel;
$data['id'] = $postId;
$data['postSchedule'] = $postSchedule;
$droppedPost->save($data);
}
From reading the FullCalendar documents my understand is that that dates should always be ISO8601 standard: https://fullcalendar.io/docs/date-parsing. So why does it not translate into my database.
我的数据库中的postSchedule列是DateTime类型。
The issue, I think is that you're not converting the
postSchedule
in correct format to be stored in thedatabase
.Controller
First, check that the data is being retrieved by
print_r($this->input->post())
.If yes, then convert the data in correct form ie
$data['postSchedule'] = date("Y-m-d H:i:s", strtotime($postSchedule));
and then store the data indatabase
with typeDATETIME
.Hope this helps you.
您能否检查jquery ajax发送的postSchedule的数据类型。我认为ajax发送postSchedule作为字符串。
我终于找到了答案。我需要在info.event.start属性上使用.toISOString()。
工作代码如下: