Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda