javascript - Sending Data VIA AJAX and getting JSON Response
Get the solution ↓↓↓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
Answer
Solution:
You have to print or echo your data inOutstandingProcessFabJSON.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, thenjson_encode()
that array
$fabDtl = $rows;// remove encode here
$fabDtlCount = count($rows);
$arr["fabDtl"] = $fabDtl;
$arr["fabDtlCount"] = $fabDtlCount;
echo json_encode($arr);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mark bundle as not supporting multiuse
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.