C#C
C#9mo ago
AideedSS

[ASKING FOR JS] Javascript wont load after post refresh [SOLVED]

this is offtopic cuz Its more about javascript, why do whenever I post refresh the second time, it wont execute my javascript code..but if I want it work, I have to refresh it or redirect to it..
<div>
   <table>
      <thead>
         <th>FILE</th>
      </thead>
      <tbody id="filelist">
         <tr>
            <td>Testinggg</td>
         </tr>
      </tbody>
   </table>
</div>

<script>
window.onload = function(){
   loadFileLibrary();
}

function loadFileLibrary(){
    let filelist = document.getElementById('filelist');
    filelist.innerHTML = '';

    getFile()
    .then(files =>{
       files.forEach(item => {
           filelist.innerHTML += `<tr>
           <td>${item.filename}</td>
           </tr>`;
       });
    }).catch(err => console.error('error :', err));
}
</script>


I go to page, it will load
FILE
____
doc.docsx
test.pdf


When I post refresh, it will still load...but If I post refresh again, it will goes just like the hardcoded
FILE
____
Testinggg


users often face this issue..And so do I, but I seen no error occurs whenever this happens
Was this page helpful?