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

173
Vistas
Do not work request fetch inside observer

I have an observer that does a check for the existence of an element in the DOM. And also, inside observer I have a fetch request which doesn't work.

Please help with the code, or explain why it doesn't work. If I make this fetch query outside of observer, it works fine.

let observer = new MutationObserver(() => {
    if (document.querySelector("any_selector")) {

        let options = {
            method: "GET",
            headers: { Accept: "application/json", "Content-Type": "application/json" },
        };

        fetch('https://any_url', options)
            .then((response) => response.json())
            .then(get_any_data);

        function get_any_data(data) {
            console.log("Work!!!");
        }

        observer.disconnect();
    }
});
observer.observe(document.querySelector("body"), { childList: true });
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