Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
Opening a json file with javascript

I am trying to open a json file in javascript,

function test() {
  
    const jsonData= require('logins.json'); 

    alert(jsonData)
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>test</title>
  <script defer src="test.js"></script>
</head>

<body>
  
</body>
    <button onclick="test()">test</button>
</html>

this is not working and logins.json is a thing, this is what is in it:


{

"Students":[
    {
        "username":"test",
        "password":"testi"    }
  ]
 }

any help is great, do I need to use Ajax or is it a silly mistake? I am new to javascript.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Node.js provides a require function which can load JSON.

You are running your JavaScript embedded in a <script> element in a web page in a browser, not Node.

do I need to use Ajax

Yes.

Give the JSON file a URL, use the fetch API to request it.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda