MUI前端代码:
内容展示页
/*
* @auth:韦小宝
* @weixin:8788981
* @qq:8788981
*/
mui.init();
mui.post('http://localhost/ThinkPHPAPI/',{
nid:'1'//这里通过POST发送数据到PHP服务器用以验证
},function(data){
//服务器返回响应,根据响应结果,分析是否登录成功;
var d=eval(data); //转换成javascript对象
var c=document.getElementById('con');
for(var i in d){
c.innerHTML=d[i].content;
}
},'json');
PHP接口实现代码:
代码基于thinkphp
/*
@qq/weixin:8788981
@auth:weixiaobao
/
class IndexAction extends Action {
public function index(){
header("Content-Type:text/html; charset=utf-8");
header('Content-type:text/json');//输出为json格式页
header("Access-Control-Allow-Origin:"); // 允许任意域名发起的跨域请求
header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
/* 判断手机端发过来的信息(预先存储手机硬件信息)再进行数据的查询判断
* 这里只是通过明文的查询,不作动态的优化
* 希望大家发挥自己的想象力,做相应的远程判断,开发更快、更安全的APP
*/
if($_POST['nid']==1){
$Con=M("News_content");
$list=$Con->where("nid=1")->select();
echo json_encode($list); //输出json
}
}
}
?>