微信应用号小程序发起请求wx.request(OBJECT)
wx.request(OBJECT)
? wx.request发起的是https请求。一个微信小程序,同时只能有5个网络请求连接。
参数名 |
类型 |
必填 |
说明 |
url |
String |
是 |
开发者服务器接口地址 |
data |
Object、String |
否 |
请求的参数 |
header |
Object |
否 |
设置请求的header , header中不能设置Referer |
method |
String |
否 |
默认为GET,有效值:OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT |
success |
Function |
否 |
收到开发者服务成功返回的回调函数,res = {data:"开发者服务器返回的内容"} |
fail |
Function |
否 |
接口调用失败的回调函数 |
complete |
Function |
否 |
接口调用结束的回调函数(调用成功、失败都会执行) |
示例代码:
wx.request({
url: ‘http://qkxue.net/‘,
data: {
x: ‘‘ ,
y: ‘‘
},
header:{
"Content-Type":"application/json"
},
success: function(res) {
var data = res.data;
}
});
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!