Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda