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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
| //ajax请求,用回调方式解决异步数据回写问题,
| //后续播放OK与NG音频统一在此写,不必每个ajax都写一遍,登录人与MAC地址都可封装在此param中(未做)
| (function(window, document) {
| var Ajax = {
| httpAsyncGet: function (url, callback) {
| $.ajax({
| url: app.API_URL_HEADER + url,
| type: "GET",
| dataType: "json",
| async: true,
| cache: false,
| success: function (data) {
| if (data.status != 0) {
| mui.alert(data.message);
| }
| callback(data);
| },
| error: function (XMLHttpRequest, textStatus, errorThrown) {
| mui.alert(errorThrown);
| },
| // beforeSend: function () {
| // },
| complete: function () {
| }
| });
| },
| // get请求方法(同步):url地址,param参数
| httpGet: function (url, param) {
| var res = {};
| $.ajax({
| url: app.API_URL_HEADER + url,
| data: param,
| type: "GET",
| dataType: "json",
| async: false,
| cache: false,
| success: function (data) {
| if (data.status != 0) {
| mui.alert(data.message);
| }
| res = data;
| },
| error: function (XMLHttpRequest, textStatus, errorThrown) {
| mui.alert(errorThrown);
| },
| // beforeSend: function () {
| // },
| complete: function () {
| }
| });
| return res;
| },
| // post请求方法(异步):url地址,param参数,callback回调函数
| httpAsyncPost: function (url, param, callback) {
| $.ajax({
| url: app.API_URL_HEADER + url,
| data: param,
| type: "POST",
| dataType: "json",
| async: true,
| cache: false,
| success: function (data) {
| if (data.status != 0) {
| mui.alert(data.message);
| }
| callback(data);
| },
| error: function (XMLHttpRequest, textStatus, errorThrown) {
| //Audio.playerAudio(Audio.type.NG,Audio.popupType.Alert,errorThrown, null);
|
| mui.alert(errorThrown);
| },
| // beforeSend: function () {
| // },
| complete: function () {
| }
| });
| },
| //数据原封返回给调用者处理
| httpPostOriginal: function (url, param, callback) {
| $.ajax({
| url: app.API_URL_HEADER + url,
| data: param,
| type: "POST",
| dataType: "json",
| async: false,
| cache: false,
| success: function (data) {
| callback(data);
| },
| error: function (XMLHttpRequest, textStatus, errorThrown) {
| mui.alert(errorThrown);
| },
| // beforeSend: function () {
| // },
| complete: function () {
| }
| });
| },
| // post请求方法(同步):url地址,param参数,callback回调函数
| httpPost: function (url, param, callback) {
| $.ajax({
| url: app.API_URL_HEADER + url,
| data: param,
| type: "POST",
| dataType: "json",
| async: false,
| cache: false,
| success: function (data) {
| if (data.status != 0) {
| mui.alert(data.message);
| }
| callback(data);
| },
| error: function (XMLHttpRequest, textStatus, errorThrown) {
| mui.alert(errorThrown);
| },
| // beforeSend: function () {
| // },
| complete: function () {
| }
| });
| },
| // ajax 异步封装
| httpAsync: function (type, url, param, callback) {
| $.ajax({
| url: app.API_URL_HEADER + url,
| data: param,
| type: type,
| dataType: "json",
| async: true,
| cache: false,
| success: function (res) {
| if (res.status == 0) {
| callback(res);
| }
| else {
| mui.alert(res.message);
| callback(null);
| }
| },
| error: function (XMLHttpRequest, textStatus, errorThrown) {
| mui.alert(errorThrown);
| },
| // beforeSend: function () {
| // },
| complete: function () {
| }
| });
| },
| };
| window.Ajax = Ajax;
| }(window, document));
|
|