I'm switching from ajax to axios, this is the code I wanted to convert.
$.ajax({
method: 'GET',
url: SPSConstants.SPS_BASE_URL + 'api/test?filter=' + encodeURIComponent(JSON.stringify(filter)),
dataType: 'json',
beforeSend: function (xhr) {
SPSUtils.getReqHeader(xhr, self, this, true);
},
}).done(function (result) {
var resultObj = JSON.parse(JSON.stringify(result));
let totalRecords = resultObj.pageInfo.total;
let currentPage = self.state.currentPage;
let currentRecords = resultObj.tollFreeNumberMasters;
if (totalRecords !== 0 && currentRecords.length === 0) {
self.setState({ currentPage: 1, pageInfo: { ...pageInfo, offset: 0 } }, () => {
self.loadTollFreeNumberTblData();
});
}
})
I've worked with axios earlier, so its not big of a deal. The only problem I'm facing is converting this part of ajax code into axios.
beforeSend: function (xhr) {
SPSUtils.getReqHeader(xhr, self, this, true);
},
is there any beforesend equivalent in axios?