I'm trying to send some data to the server asynchronously like thus:
(function($){
$(document).ready(function($){
var hiddenElement = $("#datepicker");
$("#date_search").on('click', function(e){
e.preventDefault();
if(hiddenElement.is(':visible')){
hiddenElement.datepicker().slideUp(700);
} else {
hiddenElement.datepicker({
dateFormat: "yy-mm-dd",
onSelect: function(){
var selectedDate = $(this).val();
var request = $.ajax({
url: "",
method: "GET",
data: {date: selectedDate},
dataType: "html"
});
request.done(function(msg){
});
}
}).slideDown(700);
}
})
});
})(jQuery)
<?php // front-page.php
$filter_date = isset($_REQUEST['date']) ? $_REQUEST['date'] : current_time('Y-m-d');
print_r( $filter_date );
?>
<style>
html, body, #page, #content {height: 100%;}
#datepicker {display:none;}
#searchby {list-style-type: none;}
#searchby li {float: left;padding-right: 1em;}
</style>
<ul id="searchby">
<li><a id="date_search" href="">search by date</a><div id="datepicker"></div></li>
<li><a href="">search by category</a></li>
<li><a href="">archive</a></li>
</ul>
Clicking on any date within the datepicker and the PHP script prints '2016-07-29' i.e. todays date to the screen. Not what I'm looking for. It should be printing a users selection of course.
Looking at the console I can see:
But could use a push to get it working.
Edit:
Indeed learning tricks like:
success: function(res){
console.log($(res).find("#log").text());
}
and
<p id="log"><?php print_r($filter_date); ?></p>
are beneficial.

.donefunction currently does nothing ATM.)done()with none of them working - hence the omission.successwithin the actual ajax call. IE: $.ajax({ url: "", method: "GET", data: {date: selectedDate}, dataType: "html", success: function(res) { console.log(res); } });