当前位置:Gxlcms > PHP教程 > javascript-js用json调用php并显示返回值

javascript-js用json调用php并显示返回值

时间:2021-07-01 10:21:17 帮助过:2人阅读

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

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());
    }    
    ?>

回复内容:

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

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());
    }    
    ?>

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

人气教程排行