.m.
Q: jQuery Datepicker Beforeshowday - Ajax return array of unavailable dates I am trying to get a datepicker to update a array of unavailable dates. The below works if I pass a PHP variable, but the issue I'm having seems to be returning the data for the option correctly (it is throwing a console error of cannot read undefined of 0):
jQuery(document).ready(function () {
    jQuery('#MyDate').datepicker({
        minDate: '+2',
        maxDate: new Date(2014, 1, 28),
        dateFormat: 'dd-mm-yy',

        beforeShowDay: function (date) {
            //var array = ["<?php echo $comma_seperated;?>"];

            jQuery.ajax({
                type: "POST",
                url: "/wp-admin/admin-ajax.php",
                data: {
                    action: 'unavail_dates',
                    unavaildates: '2'
                },
                success: function (output) {
                    saveVariable(output);
                }
            });

            function saveVariable(data) {
                array = '"' + data + '"';
                console.log(array);
                var string = jQuery.datepicker.formatDate('yy/mm/dd', date);
                return [array.indexOf(string) == -1];
            }
        },
        onSelect: function (dateText) {
            jQuery(this).change();
        }
    })

Note the console log displays the same as the commented var array which works. I am using a function to use the returned values from its corresponding code, but it simply returns a string of comma-separated dates and missing its first and last ". For example, 2013/12/12","2013/12/13","2013/12/14

A: The problem is you are not returning any value from the beforeShowDay method. That method does not allow asynchronous calls.
In your case, in beforeShowDay, you are sending an Ajax request and then the method returns an undefined value so all dates will be considered as valid then later the Ajax request is completed and saveVariable method gets called, but it does not have any effect on the value returned by beforeShowDay. Also there is an added problem that for every day in the calendar you are sending an Ajax request.
A proposed solution can be to load all the unavailable dates at page load and use that data in the beforeShowDay method.
Try:
jQuery(document).ready(function ($) {
    var dates;
    $.ajax({
        type: "POST",
        url: "/wp-admin/admin-ajax.php",
        data: {
            action: 'unavail_dates',
            unavaildates: '2'
        },
        success: function (data) {
            dates = data;
        }
    });

    $('#MyDate').datepicker({
        minDate: '+2',
        maxDate: new Date(2014, 1, 28),
        dateFormat: 'dd-mm-yy',
        beforeShowDay: function (date) {
            var string = $.datepicker.formatDate('yy/mm/dd', date);
            return [dates!= undefined && $.inArray(string, dates) > -1];
        },
        onSelect: function (dateText) {
            jQuery(this).change();
        }
    });
});


A: This is a bit hacky but it works. I had to create a button to call the datepicker from. Any code I tried trying the.click event on the same element seems to not update in time..deferred, etc. simply didn't fire the datepicker. I was able to get an Ajax then initialize datepicker working inserting the entire code in the HTML onclick"" in the element, but I couldn't reproduce this with.click.
Any way, my method:


*

*Create a alternative button to fire (#element).click from

*Create the Ajax function to retrieve dates in realtime (it takes about five seconds to apply if you are testing it from another page in realtime).

*Put datepicker code into a success callback.

*Fire the.click event.


Step 1: HTML of elements:
<td><input type="text" id="MyDate" name="MyDate" readonly='true' value="click here" /></td><td><input type="button" id="button" name="button" value="Select date"></td></td>

Step 2: Ajax call to find the available dates (I'm using WordPress so the URL is specific to WordPress)
AjaxGet = function () {
    jQuery.ajax({
        type: "POST",
        url: "/wp-admin/admin-ajax.php",
        data: {
            action: 'unavail_dates',
            unavaildates: '2'
        },
        success: function (output) {
            dates = jQuery.parseJSON('["'+output+'"]');
            mySuccessCallback( dates );
            console.log ( dates );
        }
    });
};

Step 3: mySuccessCallback() function from above code:
function mySuccessCallback(dates) {
    array = dates
    jQuery('#MyDate').datepicker({
        minDate: '+2',
        maxDate: new Date(2014, 1,28),
        dateFormat: 'dd-mm-yy',
        beforeShowDay: function(date) {
            var string = jQuery.datepicker.formatDate('yy/mm/dd', date);
            return [ array.indexOf(string) == -1 ];
        },
        onSelect: function(dateText) {
            jQuery(this).change();
        }
    }).change(function() {
        if (document.getElementById('date_error_row').style.visibility == 'visible') {
            document.getElementById('date_error_row').style.visibility = 'hidden';
        }
        var postid = '<?php echo esc_js($posted_id);?>';
        var pdate = jQuery(this).val(); //Select updated value

        jQuery.ajax({
            type:"POST",
            url: "/wp-admin/admin-ajax.php",
            data: {action: 'tempsave', postid: postid, postdate: pdate, status: 'waiting'},
            success:function(data){
                jQuery("#feedback").html(data);
            }
        });
        jQuery('#MyDate').datepicker('destroy');
    });
    jQuery('#MyDate').datepicker('show');
}

Step 4:
jQuery('#button').click(function() {
    AjaxGet();
});

Jan Reichert
Teen Intern
As a Teen Intern, the Serving Our Neighbors (SON) Ministries’ Hilliard Free Lunch Summer Camp for Kids has been a great experience for me as it has been an opportunity to not only get the volunteer hours needed for National Honors Society, but also to do what I love – working with children. I’m writing about the past three days (July 12 to July 14) as to me they have been the most eventful days of camp.
On July 12, the Hilliard Fire Department was kind enough to drive one of their emergency vehicles to the church and show the children everything inside. I thought this was an amazing experience for the children as they got to see what it is really like to be a firefighter, which some of the campers want to grow up and be. It was also a very fun day since they turned on the hose and let everyone run through the water. On Thursday, I got to see how “Taco Bell Jr.” desserts were made for the first time. It was a very fun experience to watch the kids work as a team to create the Oreo balls for their restaurant. It definitely helped them learn to work not only with each other but independently as well.
Lastly on Friday, I was able to see one of the campers become an entrepreneur! She had decided to make and sell her own “slime” – an awesome idea. She let the younger kids play with it before buying it which was very generous of her. It was very cool to see someone so young decide to start their own business. Free play during the course of camp was also a favorite of mine, as all the kids are so creative in how they play games, and their drawings too. Anna decided to draw my name for me on a piece of paper – which I brought home and plan to keep. This camp was an amazing experience as I got to meet a lot of new people and spend time with kind and caring kids.
At SON Ministries, people our our priority-RELATIONSHIPS are our goal!Hull agency StrawberryToo has appointed 23-year-old Jade Woodfield as its creative director.
Woodfield will manage the agency, which was set up by Strawberry recently in an attempt to retain local talent in the area, alongside Strawberry directors James Greenwood and Dominic Love.
Woodfield joined the agency as an apprentice in 2009 and was previously a designer in the Strawberry creative studio.
She said: “I’m extremely proud to have come from being trialled as an apprentice at Strawberry in 2009 to