팝업 상자를 통해 입력 한 이벤트 제목을 추가 할 수 없습니다.ajax를 사용하여 mysql 데이터베이스에 이벤트 추가
나는 내 아약스 코드를 배치이 jQuery 코드를 가지고 : 다음
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
editable: true,
events: "http://localhost/test/events.php",
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
/*
start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'http://localhost/test/add_events.php',
data: 'title='+ title+'&start='+ start +'&end='+ end ,
type: "POST",
success: function(json) {
alert('OK');
}
});
*/
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
}
});
});
나는 삽입 쿼리가 난에서 코드를 주석
<?php
$title=$_POST['title'];
$start=$_POST['start'];
$end=$_POST['end'];
// connect to the database
try {
$bdd = new PDO('mysql:host=localhost;dbname=fullcalendar', 'root', '');
} catch(Exception $e) {
exit('Can not connect to the database.');
}
$sql = "INSERT INTO evenement (title, start, end) VALUES (:title, :start, :end)";
$q = $bdd->prepare($sql);
$q->execute(array(':title'=>$title, ':start'=>$start, ':end'=>$end));
?>
기록이 add_events.php이 내 default.html 이것이 문제가있는 곳이라고 생각하기 때문입니다. 이 코드 스 니펫에 주석을 달아 볼 때 팝업 상자를 통해 이벤트를 추가 할 수 있으며 이벤트 제목을 확인한 후 이벤트 제목을 내 fullCalendar에서 볼 수 있습니다 (데이터베이스에는 아직 추가되지 않음). 그러나 해당 섹션의 주석을 제거하면 팝업 상자를 통해 입력 한 이벤트 제목이 내 fullCalendar에 나타나지 않습니다. (분명히 내 데이터베이스에 아직 추가되지 않았습니다.)
누군가 내 아약스 코드를 편집하도록 도와 줄 수 있습니까? 내 fullCalendar에 나타나는 팝업 상자를 통해 입력 된 이벤트 제목을 만들 수 있으며 데이터베이스에 성공적으로 추가 할 수 있습니다.
미리 감사드립니다.
같은 문제가 발생합니다. 여전히, 입력 된 이벤트 제목이 내 fullcalendar에 나타나지 않습니다. –