I am generating an array $array of dates in an external .php file which have this format 2014-01-10(this is Jan).
What i want to achieve is transfer this array to jquery in order to use in a Ajax success callback function.
When i print_r the array in the .php file i get:
Array ( [0] => 2013-12-10 [1] => 2013-12-10 [2] => 2013-12-11 [3] => 2013-12-12 [4] => 2013-12-12 [5] => 2013-12-12 [6] => 2013-12-16 [7] => 2013-12-16 [8] => 2013-12-16 [9] => 2013-12-16 [10] => 2013-12-17 [11] => 2013-12-17 [12] => 2013-12-17 [13] => 2013-12-17 [14] => 2013-12-18 [15] => 2013-12-18 [16] => 2013-12-18 [17] => 2013-12-19 [18] => 2013-12-19 [19] => 2013-12-20 [20] => 2013-12-20 [21] => 2013-12-20 [22] => 2013-12-20 [23] => 2013-12-20 [24] => 2013-12-20 [25] => 2013-12-23 [26] => 2013-12-23 [27] => 2013-12-27 [28] => 2013-12-27 [29] => 2013-12-27 [30] => 2013-12-27 [31] => 2013-12-27 [32] => 2013-12-27 [33] => 2013-12-30 [34] => 2013-12-30 [35] => 2013-12-30 [36] => 2013-12-30 [37] => 2013-12-31 [38] => 2014-01-03 [39] => 2014-01-05 [40] => 2014-01-07 [41] => 2014-01-07 [42] => 2014-01-08 [43] => 2014-01-08 [44] => 2014-01-08 [45] => 2014-01-08 [46] => 2014-01-08 [47] => 2014-01-08 [48] => 2014-01-08 [49] => 2014-01-08 [50] => 2014-01-09 [51] => 2014-01-09 [52] => 2014-01-09 [53] => 2014-01-09 [54] => 2014-01-09 )
What i tried is in the .php file :
$tried = implode(",", $array);
echo $tried;
And then in my .js file the jQuery :
$(document).ready(function() {
$.ajax({
type: 'POST',
url: 'php/expire.php',
data: { expired: true },
success: function(data) {
takis = data.split(',');
}
});
});
But my problem is when the array from the php file is empty the takis.length is 1 while it should be zero. Is there any other way to transfer the array without imploding like using dataType or something? Or am i doing something wrong?