[英]Sending json data via post .ajax() and also receiving a json response
[英]Sending Data VIA AJAX and getting JSON Response
我正在尝试通过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);
我需要获取DataTables Ajax调用所需的$fabDtlCount
和$fabDtl
$fabDtl
的响应。
到目前为止,我没有任何回应。 请帮我
您必须在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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.