我先前提过的问题请查看http://www.imooc.com/wenda/detail/332797
目前问题进展到了:ajax如何服务器上运行。这一步,希望大家帮帮忙,看看到底咋办,一个技术问题困住一个项目呀!!
php接口代码:
<?php header("Content-type=text/json;charset=UTF-8"); $localhost="127.0.0.1"; $user="root"; $password=""; $database="mydatabase"; $conn = mysqli_connect($localhost,$user,$password,$database); mysqli_query($conn,"set names utf-8"); $resultset = mysqli_query($conn,"select WIFIAPTag,passengerCount,timeStamp from passenger"); ////////////////////////////////////////////////准备数据进行装填 $data = array(); ////////////////////////////////////////////////实体类 class User{ public $wifi; public $count; public $time; } ////////////////////////////////////////////////处理 while($row = mysqli_fetch_array($resultset, MYSQL_ASSOC)) { $user = new User(); $user->wifi = $row['WIFIAPTag']; $user->count = $row['passengerCount']; $user->time = $row['timeStamp']; $data[] = $user; } mysqli_close($conn); // 返回JSON类型的数据 echo json_encode($data);
一瞬儿光