wx.request(OBJECT)發起https請求
第一點要注意的是微信小程序只支持https,而且需要在微信公衆平臺後臺設置配置服務器域名
考慮到前期開發階段不一定弄了https支持或一些校驗,所以可以在微信開發工具項目一欄暫時勾上關閉域名驗證這一選項,https免費配置參考教程[去看看]
(http://blog.csdn.net/u010189462/article/details/72983699)
參數和回調說明
這裏以模擬登錄爲例
loginSelf: function() {
//模擬登錄進度條
wx.showToast({
title: '登錄中...',
icon: 'loading',
})
//發起請求
wx.request({
url: 'http://xxx/user/login',
data: {
name: 'honaf' ,
password: '123456'
},
method:'post',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function(res) {
console.log(res)
//登錄成功做相應處理
if(res.data.status == 1){
wx.showToast({
title: "登錄成功",
icon: 'success',
duration: 1000
})
}
}
})
},
res打印結果如下
參考:微信公衆平臺