简体   繁体   English

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

[英]Sending Data VIA AJAX and getting JSON Response

I am trying to send data via AJAX and process them in another page with query and get the response to be processed in datatables. 我正在尝试通过AJAX发送数据,并在另一个带有查询的页面中处理它们,并在数据表中获取要处理的响应。

here is my code, 这是我的代码,

OutstandingProcess.php 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);
            }
        });

and on the OutstandingProcessFabJSON.php, 在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);

I need to get the response for $fabDtlCount and $fabDtl $fabDtl needed for DataTables ajax call. 我需要获取DataTables Ajax调用所需的$fabDtlCount$fabDtl $fabDtl的响应。

So far I get no response. 到目前为止,我没有任何回应。 Please help me 请帮我

You have to print or echo your data in OutstandingProcessFabJSON.php file. 您必须在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().

Now you want more that one value from ajax filr. 现在,您需要ajax filr提供的多个值。 So add all required values in to a array, then json_encode() that array 因此,将所有必需的值添加到数组中,然后json_encode()该数组

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM