hlsHttp.md 1.02 KB

网络工具类

APP的开发模式采用前后台完全分离的开发模式,前端代码中必不可少进行调用接口进行数据交互。

  • 1 controller中注入hlsHttp服务,此对象中主要包含postget方法。
  • 2 post 方法返回的是 promise 对象,需要传递 url 与 paramter 对象,此方法默认还会带上登录接口返回的 user_id 与 access_token (用于校验用户有没有登录),以下为post方法调用实例。access_token
  //品牌下拉框初始化
  function car_bind() {
    offsize = 1;
    var url = baseConfig.basePath + 'hls_car_bind';//接口地址
    var param = {
      "offsize": offsize,
    };
    hlsHttp.post(url, param).success(function (res) {
    //res为返回结果
      if (res.result == 'S') {
        vm.brands = res.brand_id_list;
      } else if (res.result == 'E') {
        hlsPopup.showShortCenterToast(res.message);
      }
    });
  }
  • 3 get 方法与 post类似,缺少 paramter 对象,也不会带上user_id 与access_token