Response title
This is preview!
I'm trying to disable dynamically a date using an ajax request. I manage to get the dates to block from the database through the ajax request but I can't manage to block the dates in the jquery datepicker.
Here is the ajax request :
var disabledDays = [] ; $.ajax({ type: "POST", url: "./admin/datesajax.php", data: ({idproduit: idproduit}), cache: false, dataType: "text", async: false, success: function(data) { disabledDays = data; } }); alert(disabledDays);
I receive well the dates to block form the request using this php code :
$sth1 = $dbh->prepare("SELECT datesbloquees FROM vm_datesbloquees WHERE idproduit = :idproduit" ); $sth1->execute(array(':idproduit' => $_POST['idproduit'])); $result = $sth1->fetchAll(); $tableaudatesbloquees = explode(",", $result[0]['datesbloquees']); $tableaudatesbloqueesformatjs = array(); foreach ($tableaudatesbloquees as $value) { //Modifier le format de la date et supprimer le 0 devant les jours et ajouter "" devant et derrière $datenewformat = '"'.date ('j/m/Y',strtotime($value)).'"'; //Les stocker dans un tableau array_push($tableaudatesbloqueesformatjs, $datenewformat); } //Faire une chaine de caractère des dates récupérées $string_dates_format_js = implode(",", $tableaudatesbloqueesformatjs); $string_dates_format_js_final = '['.$string_dates_format_js.']'; //Renvoyer la réponse ajax echo $string_dates_format_js_final ;
The alert result is : ["1/10/2013","2/10/2013","3/10/2013","4/10/2013"]
Then, I try to disable the dates in the datepicker using this function :
for (i = 0; i < disabledDays.length; i++) { if($.inArray(d + '/' + (m+1) + '/' + y,disabledDays) != -1) { //alert ("No !"); return [false]; } }
This code works perfectly when I hardcode the date like this (var disabledDays = ["11/10/2013", "12/10/2013"]; )but it doesn't work dynamically!
Can someone help me ?
Thank you !
© 2013 jQuery Foundation
Sponsored by and others.