-1

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

Kostas Minaidis
  • 2,819
  • 1
  • 14
  • 22
PhilB
  • 7
  • 5

0 Answers0