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));
}
);
};
}