dptrmt4366 2017-03-31 16:08
浏览 40

使用ajax从数组中获取Php变量值

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);
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能