I have some problems with Ajax and .load; I want to fire the ajax request under three circumstances. When a facility is chosen and when the preMonth/nextMonth was chosen.
My problem is that Ajax doesn't send the dates of the new month but the last active Month.
jQuery('main').on('click', '#terminstandorte select option, .nextMonth, .prevMonth', function(){
//Some Code
if (jQuery(this).get(0) == jQuery('.nextMonth').get(0)) {
jQuery('#kalender').load('?' + jQuery(this).attr('value') + ' #thisMonth',function () {
getFreeDates();
});
} else if (jQuery(this).get(0) == jQuery('.prevMonth').get(0)) {
jQuery('#kalender').load('?' + jQuery(this).attr('value') + ' #thisMonth',function () {
getFreeDates();
});
}
var werk = parseInt(jQuery('#terminstandorte select option:selected').attr('value'));
var firstDay = jQuery('.calDates .noDate:first').attr('id');
var lastDay = jQuery('.calDates .noDate:last').attr('id');
//Some Code again
function getFreeDates() {
//Hier werden alle freien Termine für den aktuellen Monat angezeigt
jQuery.ajax({
url: CENSORED,
type: "GET",
data: {
request: request,
werk: werk,
firstDay: firstDay,
lastDay: lastDay
},
contentType: 'application/json; charset=utf-8',
beforeSend: function () {
// console.log(firstDay, lastDay);
today = new Date(firstDay);
console.log(today.getMonth()+1);
},
success: function (data) {
freeDates = JSON.parse(data);
freeDates.forEach(function (date) {
});
},
error: function () {
alert('Etwas lief schief');
}
})
}
});
I tried to put the Ajax in a function, so that Ajax is called after the load, but the result is still the same.
What I am doing wrong?