Yesterday you have marked my question (Get PHP variabile in div from ajax call) as a duplicate, but it isn't! I read other questions and their answers, but in my case nothing works! I wish I could get the value of a single variable contained in array (as deposito or spese in my case) in php script, and put it in a div with ajax, i tried with data[0], data[0].deposito and data.deposito, but it shows me undefined, i do not know what to do! Is there a solution for my big problem? Thanks.
This is my default.php
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);
}
});
});
...
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);
?>