I have this code in default.php:
jQuery(document).ready(function() {
jQuery(function($) {
var $from = jQuery("#from"),
$to = jQuery("#to");
$from.datepicker({
numberOfMonths: 1,
minDate: 1,
dateFormat: 'dd-mm-yy',
onClose: function(selectedDate) {
$to.datepicker("option", "minDate", selectedDate);
}
});
$from.change(function() {
jQuery.ajax({
url: 'index.php?option=com_vehiclemanager&task=default2',
type: 'POST',
data: {
datepicker_value: $(this).val()
},
success: function(data) {
$('#result').html(data);
}
});
});
...
This is the php script:
<?php
$database = JFactory::getDBO();
$datepicker_value = isset($_POST['datepicker_value']) ? $_POST['datepicker_value'] : NULL;
$month = date("m",strtotime($datepicker_value));
$selectstring = "SELECT * FROM #__vehiclemanager_rent_sal WHERE fk_vehiclesid = 128 AND monthW = '$month'";
$database->setQuery($selectstring);
$string = $database->loadObject();
header('Content-Type: application/json');
$array[] = array(
'deposito'=>$string->deposit,
'spese'=>$string->cfee,
);
echo json_encode($array);
?>
I have a jquery datepicker in a table and i want to pick the variable from the php script via a database query with an ajax call, i can see the json object [{"deposito":"300","spese":"100"}]
but the single php variabile shows me undefined.
I inserted the task in the ajax url because the filename sends me back to the index.php, the homepage, as this is an external plugin.
I hope I explained myself and thanks for your help.