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
    }




  • 相关阅读:
    Tomcat系统架构分析
    org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcessor
    Tomcat服务器的Web安全的解决方法
    在Tomcat中实现基本的HTTP方式的验证
    在Tomcat中采用基于表单的安全验证
    Tomcat对Struts中的Action进行授权利
    在 Tomcat 上配置虚拟主机
    在Tomcat中配置单点登录
    在Tomcat中配置连接池和数据源
    Tomcat常用操作
  • 原文地址:https://www.cnblogs.com/xushan03/p/15156201.html
Copyright © 2011-2022 走看看