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

198
Vistas
How to convert jquery post API to ES6 fetch?

So I want to refactor my code from jquery to just javascript ES6, I think it will be cleaner if it implemented that way. But I'm not sure how to implement it Here is the jquery code :

$.post({
        url: /* my url */
        data: { /* my data*/ }

        beforeSend: () => {
            //do something
        },

        success: (res) => {
            //do something            
        },

        error: (err) => {
            console.error(err)
        },

        complete: () => {
            //do something
        }
    })

How to refactor to ES6 fetch to look something like this :

fetch(url, {
        method: 'POST',
        body: /* my data */
    })
     // beforeSend code
    .then((res) => res.json())
    .then((data) => {
        //do something
    })
    // complete code
    .catch((err) => console.log(err));

I will be very grateful if you can write the code with async await, but .then() .catch() is appreciated regardless. Thanks in advance

about 4 years ago · Juan Pablo Isaza
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