I want to change jQuery api call to axios api call.
jQuery code is below
$.getJSON('some_url?CART_GOODS_INFO=' + encodeURIComponent(cartData) + '&callback=?', function (data) {
if (data.IsSuccess) {
alert('success');
} else {
if ($.trim(data.ResultMessage) != '') {
alert(data.ResultMessage);
} else {
alert('failed');
}
}
});
I've tried to change this code in to axios
axios.get('some_url', {
params: {
CART_GOODS_INFO: encodeURIComponent(cartData)
}
})
.then((response) => {
console.log(response)
})
.catch((error) => {
console.log(error)
})
.then(() => {
// always executed
})
I am getting CORS error which has nothing to do with my question.
Anyways, does this seem to be the right code from 'jQuery getJSON' to 'axios get'?
I am not quite sure what that '&callback=?'
in jQuery code.
FYI. that some_url
is not the actual url. just in case if you are confused.
Anybody has any ideas, please add comment. Thanks in advance.