我很难在阅读使用JSON编码脚本创建的事件时将事件进入我的全calendar。生成JSON的脚本如下,它似乎可以正常工作,因为它正在生成JSON String Expect
get_events.php:
include("../../../../databaseconnect.php");
$sql =
"
SELECT id, title, description, start
FROM calendar
WHERE agentid='$agentid'
";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
$rows = array();
while($row = mysqli_fetch_assoc($result))
{
$rows[] = $row;
}
}
echo json_encode($rows);
get_events.php脚本在下面生成此JSON字符串 - 如前所述:
[
{
"id": "21",
"title": "My Event 2",
"description": "Electricity",
"start": "2017-03-02 00:00:00"
},
{
"id": "22",
"title": "My Event 3",
"description": "Gas",
"start": "2017-03-07 00:00:00"
}
]
但是,我所看到的只是一个空白日历。我已经测试了以下完整的脚本: -
//Tested this..
events: "http://www.example.com/PropertyIndex/applicant_calendar/fullcalendar/demos/get_events.php",
//Tested this..
events:
{
url: 'http://www.example.com/PropertyIndex/applicant_calendar/fullcalendar/demos/get_events.php',
error: function()
{
$('#script-warning').show();
}
},
没有运气。只是一个空白日历。但是,当我直接测试插入相同事件(如下)时,事件如预期时出现。
events: [
{
"id": "21",
"title": "My Event 2",
"description": "Electricity",
"start": "2017-03-02 00:00:00"
},
{
"id": "22",
"title": "My Event 3",
"description": "Gas",
"start": "2017-03-07 00:00:00"
}
]
欢迎对此有任何想法。谢谢
解决了问题。将URL设置为相对而不是完整的URL。希望有一天可以帮助别人。
events:
{
url: 'get_events.php',
error: function()
{
$('#script-warning').show();
}
},