您的位置:首页 > 产品设计 > UI/UE

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

2017-09-20 10:31 537 查看
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, CONNECT
header: { 'Content-Type':'application/json'},// 设置请求的 header

success: function (res) {

// success
console.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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: