Reputation: 975
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.
here is my code,
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,
$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.
So far I get no response. Please help me
Upvotes: 1
Views: 85
Reputation: 11987
You have to print or echo your data in OutstandingProcessFabJSON.php
file.
$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. So add all required values in to a array, then json_encode()
that array
$fabDtl = $rows;// remove encode here
$fabDtlCount = count($rows);
$arr["fabDtl"] = $fabDtl;
$arr["fabDtlCount"] = $fabDtlCount;
echo json_encode($arr);
Upvotes: 2