通过AJAX发送数据并获得JSON响应

时间:2015-10-15 09:37:26

标签: javascript php json ajax

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

这是我的代码,

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的回复 DataTables ajax调用需要$fabDtl

到目前为止,我没有得到回复。请帮帮我

1 个答案:

答案 0 :(得分: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);
相关问题