Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

303
Visualizações
How to convert beforeSend of ajax itno axios

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It seems that you want to get the xhr object before the http request. It is the Interceptors that functions similarly in the Axios.

axios.interceptors.request.use(config => {
  console.log(config);
});

However, if you set the interceptors function on an Axios instance, the callback will work for all requests from that instance. To make callback work only for specific requests, you need to create and use a new instance of Axios.

const newAxios = axios.create();
newAxios.interceptors.request.use(config => {
  console.log(config);
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda