• React后台管理系统-ajax请求封装


    1.新建文件夹 util , 在util里边新建 mm.jsx文件

    2.使用jquery里边的ajax发送请求,回调用promise,返回一个promise对象

    1. request(param){
    2.         return new Promise((resolve, reject) => {
    3.             $.ajax({
    4.                 type : param.type || 'get',
    5.                 url : param.url || '',
    6.                 dataType : param.dataType || 'json',
    7.                 data : param.data || null,
    8.                 success : res => {
    9.                     // 数据请求成功
    10.                     if(0 === res.status){
    11.                         typeof resolve === 'function' && resolve(res.data, res.msg);
    12.                     }
    13.                     // 没有登录状态,强制登录
    14.                     else if(10 === res.status){
    15.                         this.doLogin();
    16.                     }
    17.                     else{
    18.                         typeof reject === 'function' && reject(res.msg || res.data);
    19.                     }
    20.                 },
    21.                 error : err => {
    22.                     typeof reject === 'function' && reject(err.statusText);
    23.                 }
    24.             });
    25.         });
    26.     }

    3.页面引入

    1. const _mm = new MUtil();

    4.使用,传入参数

    1. // 首页数据统计
    2.    getHomeCount(){
    3.        return _mm.request({
    4.            url: '/manage/statistic/base_count.do'
    5.        });
    6.    }
  • 相关阅读:
    Visual Prolog 的 Web 专家系统 (7)
    spring来源理解-BeanFactory子类XmlBeanFactory创建过程
    Threejs 它可以在建立其内部房间效果可见
    Android AlarmManager报警的实现
    什么是注册表和注册表中的作用
    精致的外观Request
    数据仓库的工作日记_创纪录的(一)
    servlet api.jar是干什么的?
    servlet-api-2.5.jar
    用poi-3.6-20091214.jar 实现java给excel资料加密
  • 原文地址:https://www.cnblogs.com/wangyawei/p/9229234.html
Copyright © 2020-2023  润新知