I get the returned data from the Controller OK, but it needs to go to a spot in the code, as a parameter
Hello
I get the results from the controller alright as I can print-text them at a given div spot. However, I want them to go to an array as a parameter, but this array is located in another function well below the response of the controller, so as the values are local, they dont get passed down to the place I want. What this does is actually color me red the booked dates in a datepicker. Separately all the snippets do great but when I put them all together I get that problem. As you can see, for testing purposes there are hardcoded dates in the new Array, and those dates do color red the otherwise green calendar. I want my returned DATA from the controller to go into that new Array so that the dates from the DB replace those hardcoded ones.
- <script>
jQuery(document).ready(function(){
$('#boton').click(function(){
var startdate = $('#start_date').val();
var owner =1;
var user = 6;
var enddate = $('#end_date').val();
$url = '{{URL::route('reservations')}}';
$.post($url, {arrival:startdate, departure:enddate, user_id:owner, booked_by:user}, function(data){
-
- // HERE IS THE RETURNED DATA FROM THE CONTROLLER, IT IS CORRECT
$('#test').text(data);
});
});
});
$(function() {
$( "#start_date, #end_date" ).datepicker({
dateFormat: 'dd MM yy',
beforeShowDay: checkBadDates
});
});
// BUT I WANT THAT RETURNED DATA TO GO RIGHT HERE AS A PARAMETER
var $myBadDates = new Array("12 August 2015","21 August 2015");
function checkBadDates(mydate){
var $return=true;
var $returnclass ="available";
$checkdate = $.datepicker.formatDate('dd MM yy', mydate);
for(var i = 0; i < $myBadDates.length; i++)
{
if($myBadDates[i] == $checkdate)
{
$return = false;
$returnclass= "unavailable";
}
}
return [$return,$returnclass];
}
</script>