I am working on a timetable for a school shedule.
On the site, there is a jquery ui datepicker, that can be clicked to update the timetable (based on the date that has been clicked on the datepicker)
Everything works except I have to click twice to update the timetable. So every other click gets the job done.
I narrowed my problem down to several points:
I am making an ajax call inside the jquery ui datepicker onselect option. Like this:
onSelect: function (date) {
//defined your own method here
// $("#timTableMon").empty();
// $("#timTableTue").empty();
// $("#timTableWen").empty();
// $("#timTableThur").empty();
// $("#timTableFr").empty();
$.ajax({
url : 'ajaxDate.php',
dataType: 'json',
cache: false,
type : 'post',
data : {
'sendDate' : date
},
success : function(data, status) {
$("#weekHeader").text(data.week);
$("#timTableMon").html(data.Mon);
$("#timTableTue").html(data.Tue);
$("#timTableWen").html(data.Wen);
$("#timTableThur").html(data.Thur);
$("#timTableFr").html(data.Fr);
// location.reload();
// window.location.href = "http://localhost /timeTable /public/test.php";
},
error : function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "
Error:" + err);
}
}); // end ajax call
$date = $_POST['sendDate'];
// $log->log_action("date from ajax", $date);
$date = new DateTime($date);
$week = $date->format("W");
// $log->log_action("week from ajax", $week);
// $log->log_action("week from ajax", $week);
$_SESSION['week'] = $week;
$timetable->week = $week;
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.
$messages = array();
$messages['week'] = $week;
$messages['Mon'] = $timetable->drawMon();
$messages['Tue'] = $timetable->drawTue();
$messages['Wen'] = $timetable->drawWen();
$messages['Thur'] = $timetable->drawThur();
$messages['Fr'] = $timetable->drawFr();
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
echo json_encode($messages);
Any help would be greatly appreciated. Thank you