zoukankan      html  css  js  c++  java
  • 小程序 请求request, ajax封装

    let baseUrl= 'https://www.baidu.com'
    function request (url, method, data, head, dataType, doSuccess, doFail, doComplete) {
      let header = {};
      if (head == 0) {
        header = { 
            'Content-Type': 'appliaction/json',
            'cookie': wx.getStorageSync('cookieKey'),
          }
      } else if (head == 1) {
        header = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'cookie': wx.getStorageSync('cookieKey'),
          }
      }

      wx.request({
        url: baseUrl+ url,
        data: data,
        header: header,
        method: method,
        dataType: dataType,
        responseType: 'text',
        success: (res) => {
          if (typeof doSuccess == "function") {
            doSuccess(res);
          }
        },
        fail: (res) => {
          if (typeof doFail == "function") {
            doFail(res);
          }
        },
        complete: (res) => {
          if (typeof doComplete == "function") {
            doComplete(res);
          }
        },
      })
    };

    let baseUrl2= 'https://www.baidu2.com'
    function ajax(url, method, data, head, dataType, doSuccess, doFail, doComplete) {
      let header = {};
      if (head == 0) {
        header = {
          'Content-Type': 'appliaction/json',
          'cookie': wx.getStorageSync('cookieKey'),
        }
      } else if (head == 1) {
        header = {
          'Content-Type': 'application/x-www-form-urlencoded',
          'cookie': wx.getStorageSync('cookieKey'),
        }
      }
      wx.request({
        url: baseUrl2+ url,
        data: data,
        header: header,
        method: method,
        dataType: dataType,
        responseType: 'text',
        success: (res) => {
          if (typeof doSuccess == "function") {
            doSuccess(res);
          }
        },
        fail: (res) => {
          if (typeof doFail == "function") {
            doFail(res);
          }
        },
        complete: (res) => {
          if (typeof doComplete == "function") {
            doComplete(res);
          }
        },
      })
    };

    module.exports = {
      request: request,
      ajax: ajax
    }




  • 相关阅读:
    C#方法笔记二:四种类型的参数
    C#+AE 判断点是否在面内的方法
    C#:ref和out的联系及区别。
    C#+AE 调整TOCControl控件中图层的显示顺序
    C# 笔记2:面向对象
    AE10.0 Runtime绑定,如何实现
    C#+AE 用MapControl加载栅格格式文件
    Oracle 10g安装之后解锁Scott的方法
    (转载一篇)Windows7与ArcGIS Desktop9.3冲突问题解决(由QQ安装问题引出)(经本人验证已解决)
    C#方法笔记一:C#4.0新特性:命名参数和可选参数
  • 原文地址:https://www.cnblogs.com/xushan03/p/15156201.html
Copyright © 2011-2022 走看看