1.刚开始是本地测试链接数据库,传递死数据,为了将前后流程走通,也就是给定一个数据
从前台——》到后台——》前台显示;
2.现在我们是实战,直接干;
①本地测试为了方便,页面加载就请求后台数据
请求服务器:.js
onLoad: function (options) { var that = this;//=====注意此处,要用that 指代this===== wx.request({ url: 'http://localhost:8000/wxApp/showMentors', //服务器地址 method: 'get',// OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT data: { }, header: { // 设置请求的 header 'content-type': 'application/json' }, success: function (res) { console.log(res); that.setData({ //======不能直接写this.setDate====== message: res.data, //在相应的wxml页面显示接收到的数据 }); } }) },
这里需要注意的是服务器地址URL:即接口:http://localhost:8000/wxApp/showMentors
在浏览器中也可以直接访问:
说明:我是在本地测试+laravel框架,所以我的URL是:本地虚拟域名+路由:http://localhost:8000/wxApp/showMentors
路由:访问方法(laravel的路由)
Route::group(array('prefix'=>'wxApp'),function(){ Route::get