|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- //请求接口回调post
- function sendPostv2(url, requestData, callback, contentType = null) {
- // if (str == null) {
- // var str = "加载中...";
- // }
- // wx.showToast({ //显示消息提示框 此处是提升用户体验的作用
- // title: str,
- // icon: 'loading',
- // });
- var type = '';
-
- if (contentType == '1') {
- type = 'application/json';
- } else {
- type = 'application/x-www-form-urlencoded';
- }
-
- uni.request({
- url: url,
- //请求接口的url
- method: 'POST',
- //请求方式
- data: requestData,
- //请求参数
- header: {
- 'Content-Type': type
- },
- complete: function (response) {
- //请求结束后隐藏 loading 提示框
- // wx.hideToast();
- },
- success: function (response) {
- if (response.statusCode != '200') {
- callback({
- rc: '99',
- rm: '请求服务器异常_状态' + response.statusCode,
- rd: ''
- });
- return;
- }
- /* console.log(url);
- console.log(requestData);
- console.log(response.data); */
-
- callback(response.data);
- },
- fail: function (response) {
- //console.log('========发送请求失败_fai',response);
- callback({
- rc: '98',
- rm: '发送请求失败_fail',
- rd: ''
- });
- }
- });
- }
-
- module.exports = {
- sendPostv2
- };
|