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

241
Views
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
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!