-2

I am rendering a php script in my html with the jquery function load, so I want to use pure javascript now without the jquery library. Here is the code:

$(()=>{
    $('#loadTable').load('./php/loadTable.php');
})

How can I achieve this using pure javascript?

Leago
  • 11
  • 1
  • 5
  • Sixth result when searching [“\[js\] load without jquery”](https://stackoverflow.com/search?q=%5Bjs%5D+load+without+jquery) here. – Sebastian Simon Mar 13 '22 at 20:51

1 Answers1

0

Using fetch and Element.innerHTML:

fetch('./php/loadTable.php')
  .then(resp => {
    // TODO: add error handling
    return resp.text();
  })
  .then(text => {
     document.querySelector('#loadTable').innerHTML = text;
  });
AKX
  • 152,115
  • 15
  • 115
  • 172