APICloud 通过 API ajax 连接到自己的服务器数据库获取数据
这久自己在自己摸索apicloud,一直都是打算使用自己的数据库来开发,因此这里我通过一个实例来获取自己服务器数据库中的栏目信息,
PHP代码如下:
//JSON获取栏目 public function Category(){ $Category = M('news_cate')->order('sort')->select(); $this->ajaxReturn($Category); }
APICLOUD html如下:
<div class="find_nav">
<div class="find_nav_left">
<div class="find_nav_list" id="index_mun">
<ul>
<!--这里是我要获取到inde_x_mun的栏目列表-->
</ul>
</div>
</div>
<a class="search_logo" href="">搜索</a>
</div>
<script type="text/javascript">
$(function(){
apiready = function () { //注意,使用apicloud的 api时必需要使用apiready
api.showProgress();//显示加载进度框
api.ajax({
url: 'http://ww.zhix.net/Index/Index/Category', //例如:这是我的地址
method: 'post'
}, function(ret, err) {
api.hideProgress();//隐藏加载进度框
if(ret){
html = "";
for(var i=0;i<ret.length;i++){
if(i == 0){
var cl = '<li class="find_nav_cur">';
}else{
var cl = '<li>';
}
html += cl+'<a onclick="open_mun('+ret[i].id+')">'+ret[i].name+'</a></li>';
}
html +='<li class="sideline"></li>';
$('#index_mun ul').append(html);//在ul元素结尾插入html内容
}else{
api.alert({msg:('错误码:'+err.code+';错误信息:'+err.msg+'网络状态码:'+err.statusCode)});
}
});
}
});
</script>
原文 http://www.cnblogs.com/lhm166/articles/6343176.html