2015-10-15 81 views
1

我试图通过AJAX发送数据,并在另一个页面中使用查询处理它们,并获取要在数据表中处理的响应。通过AJAX发送数据并获取JSON响应

这里是我的代码,

OutstandingProcess.php

var subjob = '<?php echo $subjob; ?>'; 
     $.ajax({ 
      dataType: 'JSON', 
      type:"POST", 
      data:{subjob:subjob}, 
      url:'divpages/OutstandingProcessFabJSON.php', 
      success : function (data) { 
       alert(data.msg); 
      } 
     }); 

,并在OutstandingProcessFabJSON.php,

$subjob = $_POST['subjob']; 

$fabDtlSql = oci_parse($conn, "SELECT VFI.* FROM VW_FAB_INFO VFI WHERE VFI.PROJECT_NAME = '$subjob'"); 
oci_execute($fabDtlSql); 

$rows = array(); 
while ($r = oci_fetch_assoc($fabDtlSql)) { 
    $rows[] = $r; 
} 
$fabDtl = json_encode($rows, JSON_PRETTY_PRINT); 
$fabDtlCount = count($rows); 

我需要得到$fabDtlCount$fabDtl 响应DataTab需要$fabDtl莱阿贾克斯呼吁。

到目前为止,我没有得到任何回应。请帮助我

回答

2

您必须在OutstandingProcessFabJSON.php文件中打印或回显您的数据。

$subjob = $_POST['subjob']; 

$fabDtlSql = oci_parse($conn, "SELECT VFI.* FROM VW_FAB_INFO VFI WHERE VFI.PROJECT_NAME = '$subjob'"); 
oci_execute($fabDtlSql); 

$rows = array(); 
while ($r = oci_fetch_assoc($fabDtlSql)) { 
    $rows[] = $r; 
} 
$fabDtl = json_encode($rows, JSON_PRETTY_PRINT); 
$fabDtlCount = count($rows); 
echo $fabDtlCount;// this you can capture in ajax success(). 

现在你想要从ajax filr得到更多的值。因此,将所有需要的值添加到数组中,然后json_encode()即数组

$fabDtl = $rows;// remove encode here 
$fabDtlCount = count($rows); 
$arr["fabDtl"] = $fabDtl; 
$arr["fabDtlCount"] = $fabDtlCount; 
echo json_encode($arr); 
相关问题