gpt4 book ai didi

javascript - PHP 填充 FullCalendar,看起来不错,但数据不会显示

转载 作者:行者123 更新时间:2023-11-29 06:41:27 25 4
gpt4 key购买 nike

我正在使用 mySQL 存储有关退房日期的信息,然后根据对象我想显示已使用 FullCalendar.js 的时间

我正在使用 PHP 拉入行,然后循环遍历它们以填充创建事件的位置,当我在页面上检查时,代码看起来是正确的,但数据未加载。

这是生成页面的代码:

function getAllTimes(){
if(!empty($_GET['id']))
{
$query = "
SELECT userID, startDate, endDate
FROM checkout
Where equID =" .$_GET['id'];


global $db;
$stmt = $db->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll();
echo "<script type=\"text/javascript\">
$(document).ready(function() {

$('#calendar').fullCalendar({
events: [";
$counter = 0;

foreach($rows as $row):
if($counter == 0)
{
echo "
{
title : '".$row['userID']."',
start : '".$row['startDate']."',
end : '".$row['endDate']."'
}";
$counter = $counter+1;
}
else
{
echo ",
{
title : '".$row['userID'].",'
start : '".$row['startDate'].",'
end : '".$row['endDate']."'
}";
$counter = $counter+1;
}
endforeach;
echo "
]
});
}}";
echo "
</script>";

}
else
echo "ID must be specified";

}

getAllTimes();

这是加载时的结果,但事件并未添加到日历中。

<script type="text/javascript">
$(document).ready(function() {

$('#calendar').fullCalendar({
events: [
{
title : 'ArtemBeer',
start : '2014-01-16 00:00:00',
end : '2014-01-16 00:00:00'
},
{
title : 'ArtemBeer,'
start : '2014-01-15 00:00:00,'
end : '2014-01-16 00:00:00'
},
{
title : 'ArtemBeer,'
start : '2014-01-09 02:02:00,'
end : '2014-01-10 03:03:00'
}
]
});
}}
</script>

最佳答案

您的数据 (JS) 有一个错误的逗号:

start  : '2014-01-15 00:00:00,'

应该是:

start  : '2014-01-15 00:00:00',

还要使用你的 Chrome Inspector 通过控制台查看 JS 错误,否则你会整天猜测。

关于javascript - PHP 填充 FullCalendar,看起来不错,但数据不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21314608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com