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

381
Vistas
How to convert Ajax (Jquery) into fetch async

I wrote this code and it's works perfect for me. But when i try to convert it to fetch, dosen't work because return a promise. I don't know how to use it as a async false on fetch.

            'getProjectConstants': function(constArray)
            {
                var result='';
                $.ajax({
                type:       "GET",
                url:        `${constProjectBaseUrl}/ajax/getProjectConstants/${constArray}`,
                async:      false,
                dataType:   "json",
                success: function(data) {
                result = data
            }
        });
        return result

I tried to do like this, but dosen't work

        fetch(`${constProjectBaseUrl}/ajax/getProjectConstants/${constArray}`)
        .then((response) => response.json())
        .then((response) => {
             // console.log(response)
             return response
        }) // end of .then((response) => {
        .catch(error => {
             console.log("[ajax.getProjectConstants] Error => " + error);
        }); // end of .catch(error => {
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can try this:

async function getProjectConstants(){
    const json = await (await fetch(`${constProjectBaseUrl}/ajax/getProjectConstants/${constArray}`)).json();
    return json;
}
ajax.getProjectConstants(['PROJECT_PASSWORD_MINIMUM', 'OWNER_NAME', 'DB_TBL_TIME_ZONE']).then((constant) => {
    console.log(constant.OWNER_NAME)
}).catch(console.error);
over 4 years ago · Santiago Trujillo 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