微信小程序wx.request接收服务器返回信息

来源:互联网 发布:网络管理 编辑:程序博客网 时间:2024/04/28 04:43
1、首先要配置好微信小程序开发环境
2、配置好php服务器环境、本例中购买了3元腾讯云服务器,部署appsevr。


===============分割线=======js页面==================

Page({onLoad: function () {var that =this;//=====注意此处,要用that 指代this=====wx.request({url: 'https://43596470.qcloud.la/1.php',//此处填写你后台请求地址method: 'GET',// OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECTheader: { 'Content-Type':'application/json'},// 设置请求的 headersuccess: function (res) {// successconsole.log(res.data);//在控制台输出向服务器接收到的数据that.setData({ //======不能直接写this.setDate======result11: res.data.message, //在相应的wxml页面显示接收到的数据});},fail: function (res) {// fail},complete: function (res) {// complete}})}})




===============分割线=======wxml页面==================
<view>{{result11}}</view>



===============分割线=======1.php页面==================

<?php$response =array('id'=>666,'message'=>'sucess for me','name'=>'hello dog');echo json_encode($response);?>


========================================================
参考:
http://www.henkuai.com/thread-16097-1-1.html
http://www.icvo.net/archives/21

原创粉丝点击