从Ajax调用获取div中的PHP可变性 [英] Get PHP variabile in div from ajax call

查看:70
本文介绍了从Ajax调用获取div中的PHP可变性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在default.php中有以下代码:

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);
        }
      });
    });

    ...

这是php脚本:

<?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);
?>

我在表中有一个jquery datepicker,我想通过一个带有ajax调用的数据库查询从php脚本中选择变量,我可以看到json对象[{"deposito":"300","spese":"100"}] 但单一的php可变显示我未定义. 我将任务插入到ajax url中,因为文件名将我发送回首页index.php,因为这是一个外部插件. 希望我能解释自己,并感谢您的帮助.

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.

推荐答案

而不是$(this).val(),请尝试引用实际元素.像这样的东西:$('#from').val().

Instead of $(this).val(), try referencing the actual element. Something like this: $('#from').val().

这篇关于从Ajax调用获取div中的PHP可变性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆