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

197
Vistas
How to use javascript after fetch call

I am loading a PHP file into a div using fetch. The code is:

let FC = fetchphp ('contents/my_stuff/my_work.php', LNG, main_place);
}

function fetchphp (XX, LNG, main_place) {
  
  let place = document.getElementById(main_place);
 
  fetch(XX, { method: "POST", body: LNG })
  .then(res => res.text())
  .then((txt) => {
    console.log(txt);
     place.innerHTML = txt;
  })
  .catch((err) => { console.error(err); });
  return false;
}

The PHP code produces the output properly, but none of the console.log calls in the PHP file (head section) e.g.:

<script> console.log('HEAD Top of mywork A -- from my_work.php'); </script>

produce anything in the browser (Chrome) console. And no JS works either.

This seems rather bizarre. All the file content shows in the console in the above:

console.log(txt);

But that is not much use. How does one get JS to work on a page/file has been loaded with fetch?

PhilB

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