'What is the equivalent of the jQuery function load() in javascript? [duplicate]
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?
Solution 1:[1]
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;
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AKX |
