-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6-1.封装的ajax请求数据.txt
41 lines (40 loc) · 1.24 KB
/
6-1.封装的ajax请求数据.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
1.app.js里面的写法
//接口入口
appRequest : function(sendData){
var that = this;
if( !sendData.data ){sendData.data={}}
//插入参数
sendData.data.token = that.data.userInfo.token;
sendData.data.app_ed = that.data.logmsg.app_ed;
sendData.data.wechat_type = that.data.logmsg.wechat_type;
//发起请求
wx.request({
url: sendData.urls,
data : sendData.data ,
header: {'content-type': 'application/json' },
success: function(res) {
if( typeof(sendData.success)=="function"){ sendData.success(res)}
if( sendData.isregister && res.data.c == "0"){that.data[sendData.isregistername] = res.data.d;}
},
fail: function(res) {
console.log('接口错误', res , sendData);
if( typeof(sendData.fail)=="function"){ sendData.fail(res)}
}
})
},
2.接口的使用
//请求抽奖接口
app.appRequest({
urls : app.data.API.ARENA_CONFIG,
isregistername : 'arena_config',
isregister : true,
success : function(res){
console.log('ARENA_CONFIG',res);
if( res.data.c == '0'){
that.setData({arena_config:res.data.d})
// console.log('11111111111111111',app.data.arena_config);
}else{
wx.showToast({ title: let_res.data.m,icon: 'none',duration: 1000})
}
}
})