douhuanchi6586 2015-10-15 09:37
浏览 32

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

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

  • 写回答

1条回答 默认 最新

  • doutui7955 2015-10-15 09:41
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教