Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
Error de referencia no detectado: el requisito no está definido en el navegador

cuando ejecuto el archivo js donde está escrita esta función, funciona y muestra datos en la consola. pero cuando lo ejecuto en un navegador desde el archivo html con un clic, aparece el error: Error de referencia no detectada: el requisito no está definido. Intenté usar la función en la etiqueta pero no funcionó.

 function appendData() { const data = require("../assets/Data/Courses.json"); var length = Object.keys(data.employees).length; var Text = new Array(); for(let i = 0; i < length; i++) { //document.getElementById('test').innerHTML += "<br>"+data.employees[i].firstName + " " + data.employees[i].lastName ; Text[i] = data.employees[i].firstName+ " " + data.employees[i].lastName ; console.log(Text[i]); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

require() es en realidad el estilo Node de importar código. Así que no funcionará en este caso. No conozco su configuración, pero si está usando Vanilla JS (sin la configuración de Babel), puede incluir archivos .json en su código utilizando la API de fetch .

 fetch("../assets/Data/Courses.json") .then(response => { const data = response.json(); var length = Object.keys(data.employees).length; var Text = new Array(); for(let i = 0; i < length; i++) { //document.getElementById('test').innerHTML += "<br>"+data.employees[i].firstName + " " + data.employees[i].lastName ; Text[i] = data.employees[i].firstName+ " " + data.employees[i].lastName ; console.log(Text[i]); } }) .then(data => console.log(data)) .catch(error => console.log(error));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!