You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http.js 1.5KB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //请求接口回调post
  2. function sendPostv2(url, requestData, callback, contentType = null) {
  3. // if (str == null) {
  4. // var str = "加载中...";
  5. // }
  6. // wx.showToast({ //显示消息提示框 此处是提升用户体验的作用
  7. // title: str,
  8. // icon: 'loading',
  9. // });
  10. var type = '';
  11. if (contentType == '1') {
  12. type = 'application/json';
  13. } else {
  14. type = 'application/x-www-form-urlencoded';
  15. }
  16. uni.request({
  17. url: url,
  18. //请求接口的url
  19. method: 'POST',
  20. //请求方式
  21. data: requestData,
  22. //请求参数
  23. header: {
  24. 'Content-Type': type
  25. },
  26. complete: function (response) {
  27. //请求结束后隐藏 loading 提示框
  28. // wx.hideToast();
  29. },
  30. success: function (response) {
  31. if (response.statusCode != '200') {
  32. callback({
  33. rc: '99',
  34. rm: '请求服务器异常_状态' + response.statusCode,
  35. rd: ''
  36. });
  37. return;
  38. }
  39. /* console.log(url);
  40. console.log(requestData);
  41. console.log(response.data); */
  42. callback(response.data);
  43. },
  44. fail: function (response) {
  45. //console.log('========发送请求失败_fai',response);
  46. callback({
  47. rc: '98',
  48. rm: '发送请求失败_fail',
  49. rd: ''
  50. });
  51. }
  52. });
  53. }
  54. module.exports = {
  55. sendPostv2
  56. };