javascript - js用json调用php并显示返回值
高洛峰
高洛峰 2017-04-10 13:12:41
[JavaScript讨论组]

图片1是一个接送记录,图片2是这个记录的一个接口,怎么用js调用这个php然后在网页上显示那些返回值,怎么弄的,php中的代码也附上了

<?php

require('../../../incode/user_fns.php');

function __autoload($class_name) {
    require_once '../../../incode/'.$class_name.'.php'; 
}   

if (isset($_COOKIE['userid'])) {
    $userid = intval(trim($_COOKIE['userid']));
} else {
    error_exit(ENOPOST);
}   
if (isset($_COOKIE['token'])) {
    $usertoken = trim($_COOKIE['token']);
} else {
    error_exit(ENOPOST);
}
if (!$usertoken || !$userid) {
    error_exit(ENOPOST);
}
if (isset($_POST['year'])) {
    $year = intval(trim($_POST['year']));
} else {
    error_exit(ENOPOST);
}   
if (isset($_POST['month'])) {
    $month = intval(trim($_POST['month']));
} else {
    error_exit(ENOPOST);
}
if (!$year || !$month) {
    error_exit(ENOPOST);
}

$page = 0;
if (isset($_POST['page'])) {
    $page = intval(trim($_POST['page']));
}   
$count = 10;
if (isset($_POST['pcount'])) {
    $count = intval(trim($_POST['pcount']));
}   
    try{
db_connect();
$registry =& Registry::getInstance();
$conn =& $registry->get('dbconn');
if (!check_accesstoken($userid, $usertoken)) {
    error_exit(EUSERTOKEN);
}

$result = $conn->query("select bbid from user where userid=$userid");
if (!$result) {
    error_exit(EDBSELECT);
}
$row = $result->fetch_row();
if (!$row) {
    error_exit(EBABYNOTEXIST);
}
$bbid = $row[0];
$result = $conn->query("select cardid from accesscard where bbid=$bbid");
if (!$result) {
    error_exit(EDBSELECT);
}

$resultarray = array();

$starttime = strtotime("$year-$month-1");
$month++;
$endtime = strtotime("$year-$month-1");

$pagestart = $page*$count;
$result = $conn->query("select checkid,parent,time,status from checkin where bbid=$bbid and time>$starttime and time<$endtime order by time desc limit $pagestart,$count");     
if (!$result) {
    error_exit(EDBSELECT);
}   

while ($row = $result->fetch_row()) 
{
    if (connection_aborted() || connection_status()!=CONNECTION_NORMAL) {
        exit;
    }
    $lasttime = $row[2];

    $checkin['checkid'] = $row[0];
    $checkin['parent'] = $row[1];
    if (!$row[1]) {
        $result1 = $conn->query("select name from user a,checkin b where b.checkid='".$row[0]."' and a.userid=b.cardid");
        if (!$result1) {
            error_exit(EDBSELECT);
        }
        $row1 = $result1->fetch_row();
        if (!$row1) {
            continue;
        }
        $checkin['teacher'] = $row1[0];
    }       
    $checkin['time'] = $lasttime;
    $checkin['status'] = $row[3];       
    $resultarray[] = $checkin;
}

echo json_encode($resultarray);
    }catch (Exception $e) {
error_exit($e->getCode());
    }    
    ?>
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
伊谢尔伦

建议先看看这篇文章吧 -- json在php和js中的玩转

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号