I have quite a strange problem. My form checks for availability. And after that it halts or allows the process to continue. Or at least. It should.
In my navigation function I have the following code:
    var available = check_availability(BookingStart + ' ' + StartTime, BookingEnd + ' ' + EndTime);
    if (available === false) {
        alert('not available');
        console.log('our function says unavailable');
        // *** UNAVAILABLE LOCATION FOR THIS PERIOD
        return false;
    }
This loads the results from the check_availability() function and if true it allows to proceed and if false, doh... halts it.
However this is the intended way to go.
My check_availability() code :
function check_availability(start, end) {
    if (!$('#availability_message').hasClass('hidden')) {
        $('#availability_message').addClass('hidden');
    }
    console.log('checking availability for : ' + start + ' - ' + end);
    $.ajax({
        type: 'POST',
        url: '{@FullAppBase}ajaxcall/availability',
        data: {
            'booking_start': start,
            'booking_end': end,
        },
        ///######## IN CASE OF SUCCESS
        success: function (response) {
            console.log('avb : ' + response);
            if (response == 1) {
                console.log('en b btn');
                $('#availability_message').addClass('hidden');
                return true;
            }
            else {
                console.log('dis b btn');
                $('#availability_message').removeClass('hidden');
                return false;
            }
        },
        error: function (response) {
            console.log('error: ' + response);
        }
    }
    );
}
Whenever I check what the console says it works just fine. Whenever I hard code : available = false.. It works as well. But I want it to be dynamic of course.
    var available = check_availability(BookingStart + ' ' + StartTime, BookingEnd + ' ' + EndTime);
    available = false;
    if (available === false) {
        alert('not available');
        console.log('our function says unavailable');
        // *** UNAVAILABLE LOCATION FOR THIS PERIOD
        return false;
    }
To me this makes no sense. Since the variable available should have the boolean true / false in it already.
But when I display it on screen with alert :
I get :
available = undefined
To my logic this makes no sense. But I am probably missing something. Could anyone tell me where I am going wrong?
Edit For what I understand is that this is because it is an async call. But I also know that
$.ajax({
    type: 'POST',
    url: '{@FullAppBase}ajaxcall/availability',
    async: false,
    data: {
Is not working anymore.
But should I rebuild the code to do :
call A {
   response {
    call B {
       response {
         call C {
                }
       }
     }
  }
}
Do I understand that one correctly?
