Home > OS >  issue to load data from a .js file
issue to load data from a .js file

Time:10-04

I am trying to run a web page with that js file, for some reason, it doesn't want to work and when I try the console it says "Live reload enabled". Does anyone know how I can solve that issue? .

const container = document.querySelector('.datalink')
let listdata = async() => {

    let url = '  http://localhost:3000/indusboards';
    const urlfetch = await fetch(url);
    const urlfound = await urlfetch.json();
    let template = '';
    datafound.array.forEach(element => {

        template  = `
             <div class ="element">
             <p><small>${element.serialno}</small></p>
             <p><small>${element.boardtest}</small></p>
             <p><small>${element.testresul}</small></p>
             <p><small>${element.serialno}</small></p>
             <p><small>${element.testdate}</small></p>
             <p><small>${element.testtime}</small></p>
             <p><small>${element.boardlocation}</small></p>
             <a href = "/json_projet/details.html">.... more</a>
             </div>
         
         `
    })

    container.innerHTML = template;
}


window.addEventListener('DOMContentLoarded', () => listdata());

CodePudding user response:

You made a spelling mistake change your code to.

window.addEventListener('DOMContentLoaded', () => listdata());

Instead of

window.addEventListener('DOMContentLoarded', () => listdata());

or you could use

window.onload = () => {
    listdata()
}

CodePudding user response:

How about this?

const container = document.querySelector('.datalink')
let listdata = async() => {

    let url = '  http://localhost:3000/indusboards';
    const urlfetch = await fetch(url);
    const urlfound = await urlfetch.json();
    let template = '';
    datafound.array.forEach(element => {

        template  = `
             <div class ="element">
             <p><small>${element.serialno}</small></p>
             <p><small>${element.boardtest}</small></p>
             <p><small>${element.testresul}</small></p>
             <p><small>${element.serialno}</small></p>
             <p><small>${element.testdate}</small></p>
             <p><small>${element.testtime}</small></p>
             <p><small>${element.boardlocation}</small></p>
             <a href = "/json_projet/details.html">.... more</a>
             </div>
         
         `
    })

    container.innerHTML = template;
}


window.addEventListener('DOMContentLoaded', () => listdata());
  • Related