wx.request(Object object)
发起 HTTPS 网络请求
参数:
url:开发者服务器接口地址
data:请求的参数
header:设置请求的 header,header 中不能设置 Referer。content-type:application/json
method:HTTP 请求方法
dataType:返回的数据格式
responseType:响应的数据类型1.7.0
success:接口调用成功的回调函数
fail:接口调用失败的回调函数
complete:接口调用结束的回调函数(调用成功、失败都会执行)
最终发送给服务器的数据是 String 类型,如果传入的 data 不是 String 类型,会被转换成 String 。
实例
wx.request({
url: 'test.php',
data: {
x: '',
y: ''
},
header: {
'content-type': 'application/json'
},
success (res) {
console.log(res.data)
}
})