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

249
Vistas
Convert jquery ajax to fetch

Does someone knows jquery and can help me convert this ajax to js fetch ? Unfortunately, I don't know jquery and I need to convert this into js fetch.

function ajaxLogoutDetailsApi() {
  $.ajax({
    type: "GET",
    url: "OIDCGetLogoutDetails",
    async: false,
    cache: false,
    data: "json",
    success: function (data, status, xhr) {
      data = data.replace('\/\*', '');
      data = data.replace('\*\/', '');
      var dataJson = JSON.parse(data);
      if (dataJson.logoutUrl != null) {
        document.location.href = dataJson.logoutUrl;
      }
    },
    error: function (xhr, status, err) {
      console.log("error in ajaxLogoutDetailsApi");
    }
  });
}

Appreciate every hint.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I was going to use async/await but since there's that odd replacing before the JSON gets parsed I've reverted to old-school fetch with "thenables".

function ajaxLogoutDetailsApi() {
  
  const endpoint = 'OIDCGetLogoutDetails';
  
  // Fetch the JSON
  fetch(endpoint)

    // This is returned as the first argument
    // of "then"
    .then(json => {

      // Weird replacement stuff
      const updated = json
        .replace('\/\*', '')
        .replace('\*\/', '');

      // Parse the JSON
      const data = JSON.parse(updated);

      // Set the new page if the condition is met
      if (data.logoutUrl) {
        window.location.href = data.logoutUrl;
      }

    })

    // Catch any errors
    .catch(error => {
      console.error('Error:', error);
    });

}

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