我仍然是一个新的程序员,并且我得到这段代码的工作(我从here得到)有问题。它使用MySQL来存储数据。我想了解所有这些部分,但我现在才开始理解ajax和jQuery是如何协同工作的。Fullcalendar没有显示数据
它用于显示数据,它依赖于“events.php”。我已经单独运行了它,它生成的JSON应该可以在日历中显示,所以我知道SQL工作正常,但它不会显示在主页面上。到库,CSS等的路径已被更改,但插入到MySQL表中的函数工作正常......所以我可以使用它来插入日期,但是一旦出现,它们不会显示在刷新。
编辑:已解决。据我所知,有三个问题的组合:(1) - 确保返回的JSON没有“false”引号。 (2)确保你有jquery.min.map。 (这是通过查看Chrome的调试器发现的),以及(3)我不能使用该文件的路径......我只是将其称为“events.php”。感谢大家帮助!
下面是下面的html ...和下面的那个JSON。我看到其他几个职位,从未有过的解决方案,所以很明显,任何帮助,不胜感激:
<!DOCTYPE html>
<html>
<head>
<link href='fullcalendar/fullcalendar.css' rel='stylesheet' />
<script src='lib/jquery.min.js'></script>
<script src='lib/jquery-ui.custom.min.js'></script>
<script src='fullcalendar/fullcalendar.min.js'></script>
<script>
$(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,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: "http://localhost/tpsdb/fullcalendar/events.php",
// Convert the allDay from string to boolean
eventRender: function(event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
var url = prompt('Type Event url, if exits:');
if (title) {
var start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
var end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'http://localhost/tpsdb/fullcalendar/add_events.php',
data: 'title='+ title+'&start='+ start +'&end='+ end +'&url='+ url ,
type: "POST",
success: function(json) {
alert('Added Successfully');
}
});
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
eventDrop: function(event, delta) {
var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'http://localhost/tpsdb/fullcalendar/update_events.php',
data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
type: "POST",
success: function(json) {
alert("Updated Successfully");
}
});
},
eventResize: function(event) {
var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
$.ajax({
url: 'http://localhost/tpsdb/fullcalendar/update_events.php',
data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
type: "POST",
success: function(json) {
alert("Updated Successfully");
}
});
}
});
});
</script>
<style>
body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
由events.php页面生成的JSON:
[{"id":"7","title":"test","start":"2014-02-05 00:00:00","end":"2014-02-05 00:00:00","url":"","allDay":"false"},{"id":"8","title":"Title 2","start":"2014-02-06 00:00:00","end":"2014-02-06 00:00:00","url":"","allDay":"false"},{"id":"9","title":"Feb 1","start":"2014-01-28 00:00:00","end":"2014-01-28 00:00:00","url":"","allDay":"false"}]
下面是创建的PHP JSON根据正确的格式去除引号(true不会出现在我的JSON字符串中)。
<?php
// List of events
$json = array();
// Query that retrieves events
$requete = "SELECT * FROM evenement ORDER BY id";
// connection to the database
include ("../includes/functions.php");
// Execute the query
$resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));
// sending the encoded result to success page
$tempjson = json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));
$tempjson = str_replace('"false"', 'false', $tempjson);
echo $tempjson;
?>
在我的传奇更多信息 - 它可以帮助那些在我的后尘:显然这是所提供的lib不包括jquery.min.map(我还没有研究那是什么)。感谢您询问Chrome中的f12控制台。我看到min.map丢失了。仍然没有帮助我,虽然:(工作...
这里是Chrome的浏览器的屏幕截图。
你能提供从您的JavaScript控制台输出?如果您使用的是Chrome,则可以按F12访问开发工具(在Windows上)。 –
感谢您的建议。我发现我缺少jQuery.min.map,所以我把它放在那里,尽管它没有使它工作。看看我张贴的截图,还有其他建议吗? –
如果您点击该红色失败请求,并且转到响应选项卡,那里有什么吗? http响应代码如何? –