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

243
Visualizações
Creating a GET request to display images from JSON file

I'm new to Javascript and have been spinning on writing this piece of code in order to display a series of pictures on a page from an external source, sort of like an instagram feed, using a GET request through jQuery. I have been given a JSON file that contains an array of image URLs, some of which I want to exclude because they are broken.

Here is the code that I've written thus far - I've tested it and it doesn't work and I'm looking for some guidance on what aspects I may be missing in order to get my code to work:

$(document).ready(function () {
    $('imagesFromJSON').click(function () {
        $.getJSON("images.json", function (data) {

            var arrItems = [];      // The array to store JSON items.
            $.each(data, function (index, value) {
            arrItems.push(value);       // Push values in the array.
            });

            for (let i = 0; i < arrItems.length; i++) {
                if (arrItems[i].contains('fakeurl') === false) {
                let img = document.createElement('img');
                img.src = arrItems[i].Image
                document.querySelector('.container').appendChild(image)
                }
            }
        });
    });
});
<html>
<head>
  <meta charset="UTF-8">
  <title>Feed Test</title>
  <script type='text/javascript' src='feed.js'></script>
  <script src="jquery-3.6.0.min.js"></script>
</head>

<body>

<h1>FEED TEST</h1>

<p><input type="button" id= "imagesFromJSON" value="Show Images" /></p>

<div class="container"></div>

</body>
</html>

about 4 years ago · Juan Pablo Isaza
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