$(document).ready(function() {
redo(1);
$("select").change(function () {
var str = "";
$("select option:selected").each(function () {
str = $(this).val() + " ";
});
console.log(str);
redo(str);
});
// page is now ready, initialize the calendar...
function redo(t) {
$.getJSON("getPrenotazioni.php",{action:"date","cameraid":t}, function(data){
$('#calendar').html("");
console.log(data);
$('#calendar').fullCalendar( 'rerenderEvents' );
$('#calendar').fullCalendar({
editable: false,
events: data,
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
});
});
$('#calendar').fullCalendar( 'refetchEvents' );
}
});
And the PHP code is:
<?php
$d = getVids($db,'ji_prenotazione','da_data,a_data','WHERE cameraid='.$_GET['cameraid']);
switch ($_GET['action'])
{
case 'date':
if (count($d)>0) {
for($i=0;$i<count($d);$i++)
{
$str[] = array('title' => utf8_encode('xxx'),'start'=>$d[$i]['da_data']."T08:30",'end'=>$d[$i]['a_data']."T08:30");
}
}
else
$str[] = array('title' => '','start'=>'','end'=>'');
$json = array('events'=>($str));
break;
}
echo json_encode($json);
?>
It seems to work but if I change something into the database, for example, if I delete all entries and refresh the webpage, the previous values are still there in the calendar.
What am I missing?
The reason I asked what browser you are using is because all browsers behave different when executing AJaX requests. Basically a browser listens to several ‘headers’ inside a request response. One of these ‘headers’ sets the expiration date for the data downloaded, which you don’t set (assuming this is the complete code). If you keep requesting data over the same URL, you will get the ‘cached’ result instead of the new result.
Forcing the browser to request new data every time can be done through PHP, using the
header()function. Note that this function has to be called before any output is sent to the browser. The headers you have to include are like this:The first header will (obviously) tell the browser to revalidate the content on every request, the second will invalidate the cache immediately (which is used in older browsers).
Another option to do this, using Javascript instead of PHP, is to alter the URL on every request. This is not the best option, since it will create new cache data on every reload of the page, but it will work. You can do this by adding some random URL data (like
"getPrenotazioni.php?id=" + Math.random()).Note that I am far from sure that this is your problem, but it is likely considering your code you provided. You can simply check this by opening the page in IE (or any other browser that you had already open) after you made a change and see if the pages differ amongst browsers. Alternatively you can load the page after you made change and if nothing changed, clear your cache and reload (
CTRL + F5).