weixin_33681778 2019-08-09 22:11 采纳率: 0%
浏览 234

将Ajax jQuery转换为Axios

My page was using ajax requests but we are moving them to axios. I have changed the code but the response data is coming empty.

This was my old code:

export function getMList(params, onSuccess, onFailure) {
    const url = `/admin/list`;
    const {
        name,
        type
    } = params;

    return $.ajax({
        type: 'GET',
        url,
        processData: false,
        contentType: 'application/x-www-form-urlencoded',
        data: $.param({name, type}),
        success: (response) => {
            onSuccess(response);
        },
        error: (error) => {
            onFailure(error);
        }
    });
}

Now after changing it to axios it is :

export function getMList(params) {
    const {
        name,
        type
    } = params;

    axios.get(`/admin/list`,params,{
        headers : {'contentType': 'application/x-www-form-urlencoded' 
        }
    }).then((res) => { return res; }, (err) => { return err; })
}

What am I doing wrong. Is it the data I am passing as params ?

The query is used here :

export function getMList(id, name, type) {
    const encodedName = encodeURI(name);

    return (dispatch) => {
        dispatch(requestMList({ id }));
        admin.getMList({ name: encodedName, type },
            (response) => {
                dispatch(receivedMList({ id, name, type, response }));
            },
            (error) => {
                dispatch(failedMList(id));
            }
        );
    };
}
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题