For some reason I cannot get my JSON feed (which is assembled via php) to show up on my Fullcalendar plugin. The JSON is valid and works great if I hardcode it as an event source. But when it's being fetched via URL, nothing shows! I know several people have had this same problem, but either it has not been answered yet or their solution doesn't seem to work for me. Any help on this is much appreciated, as I have stared at this for two days and can't catch a break.
由于某些原因,我无法获得JSON提要(通过php组装)以显示在Fullcalendar插件上。如果我将JSON硬编码为事件源,它是有效的,并且工作得很好。但当它通过URL获取时,什么也看不见!我知道有几个人也有同样的问题,但要么还没有得到解决,要么他们的解决方案似乎对我不起作用。任何帮助都是非常感谢的,因为我已经盯着这两天了,不能休息。
Here is my js
这是我的js
$(function()
{
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: false,
minTime: 7,
maxTime: 20,
slotMinutes: 15,
eventRender: function (event, element) {
element.find('.fc-event-title').html(event.title);
},
events: {
url: "http://mywebsite.com/js/schedule_feed.php",
data: {locationID: <?=$locationID?>},
type: "POST",
error: function () {
alert('there was an error while fetching events!');
},
},
});
});
And here is my php:
这是我的php:
<?php
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("mydatabase") or die(mysql_error());
$query = "select schedule.schedule_id, schedule.type, schedule.show, schedule.schedule_date, patients.fname, patients.lname
from schedule
LEFT JOIN patients
ON schedule.patient_id=patients.patient_id
WHERE patients.locationID='".$_POST['locationID']."'";
$res = mysql_query($query) or die(mysql_error());
$events = array();
while ($row = mysql_fetch_assoc($res)) {
$eventsArray['id'] = $row['schedule_id'];
$eventsArray['title'] = ucfirst(strtolower($row['lname'])) . ", " . ucfirst(strtolower($row['fname'])); //. $isNewCustomer;
$eventsArray['start'] = strtotime($row['schedule_date']);
$timestamp = strtotime($row['schedule_date']) + 60*30;
$eventsArray['end'] = $timestamp;
$eventsArray['backgroundColor'] = '#999';
$eventsArray['textColor'] = '#fff';
$eventsArray['url'] = 'http://'.$_SERVER['HTTP_HOST'].'/index.php/schedule/edit_appt/' . $row['schedule_id'];
$eventsArray['allDay'] = false;
$eventsArray['editable'] = false;
$eventsArray['timeFormat'] = 'h(:mm)';
$events[] = $eventsArray;
}
echo json_encode($events);
?>
Once again, if I type in my php url directly into the browser, it provides me with valid JSON. If I copy that JSON feed from the browser and hardcode it directly into the JS...it works! What the heck is going on? Thank you in advance!
同样,如果我将php url直接输入浏览器,它将为我提供有效的JSON。如果我从浏览器中复制JSON提要并直接将其硬编码到JS中……它的工作原理!到底是怎么回事?提前谢谢你!
1 个解决方案
#1
1
I figured it out!!! For anyone who runs into this same issue, it has something to do with cross domain ajax. You can read about it on the following link: Origin is not allowed by Access-Control-Allow-Origin
我搞懂了! ! !对于任何遇到同样问题的人来说,它与跨域ajax有关。您可以在以下链接上阅读:访问控制允许的起源是不允许的
I just added this code to the top of my php script:
我只是将这段代码添加到php脚本的顶部:
<?php header('Access-Control-Allow-Origin: http://www.mydomain.com'); ?>
#1
1
I figured it out!!! For anyone who runs into this same issue, it has something to do with cross domain ajax. You can read about it on the following link: Origin is not allowed by Access-Control-Allow-Origin
我搞懂了! ! !对于任何遇到同样问题的人来说,它与跨域ajax有关。您可以在以下链接上阅读:访问控制允许的起源是不允许的
I just added this code to the top of my php script:
我只是将这段代码添加到php脚本的顶部:
<?php header('Access-Control-Allow-Origin: http://www.mydomain.com'); ?>