Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8981943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:27:39+00:00 2026-06-15T20:27:39+00:00

This is somewhat pseudo code so EDIT away. I want to make it when

  • 0

This is somewhat pseudo code so EDIT away. I want to make it when the user clicks on a thumb inside #placeholder DIV thumb2 is then displayed inside #imageLoad DIV. NOTE: Thumb and thumb2 are JSON items. A lot of people are saying that this can’t be done with getJSON because it’s an asynchronous request. If that is the case, then how can I change my script to support the request? If I am going the wrong way, please provide alternate solutions.

$.getJSON('jsonFile.json', function (data) {
    var image1 = "<ul>";
    for (var i in data.items) {
        image1 += "<li><img src=images/items/" + data.items[i].thumb + ".jpg></li>";
    }
    image1 += "</ul>";
    document.getElementById("placeholder").innerHTML = output;

    var image2 = "<img src=images/items/" + data.items[i].thumb2 + ".jpg>";
    $('li').click(function () {
        document.getElementById("imageLoad").innerHTML = output;
    });
});

Here is the external JSON file below (jsonFile.json):

{"items":[
    {
        "id":"1",
        "thumb":"01_sm",
        "thumb2":"01_md"
    },
    {
        "id":"2",
        "thumb":"02_sm",
        "thumb2":"02_md"
    }
]}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:27:40+00:00Added an answer on June 15, 2026 at 8:27 pm

    You can try something like the following:

    $.getJSON('jsonFile.json', function(data)
    {
      $("#placeholder").html("");
      var ul = $('<ul></ul>');
      $('#placeholder').append(ul);
      var load = $("#imageLoad");
    
      for(var i in data.items)
      {
        var li = $('<li></li>');
        ul.append(li);
        var img = $('<img>');
        img.attr("src", "images/items/" + data.items[i].thumb + ".jpg");
        img.click((function(x)
        {
          return function()
          {
            load.html("<img src=images/items/" + data.items[x].thumb2 + ".jpg>");
          }
        })(i));
        li.append(img);
      }
    });
    

    Main difference is that click-handler is assigned inside the loop, so every handler receives a closure with appropriate reference to thumb2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need you to humor me during this question. This is somewhat pseudo code
Once and for all I want to clearify this somewhat subjective and argumentative area
I have a XML source with nodes like this (Somewhat anonymized): <XXX> <Code A=oa
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
This is somewhat complex (well to me at least). Here is what I have
this is somewhat of an odd question. I wrote a C function. Its 'like'
This is somewhat of a sequel to Slow Exists Check . Alex's suggestion works
This is somewhat similiar to this : pthread function from a class But the
This is somewhat related to the question posed in this question but I'm trying
I know this is somewhat subjective, but I can't find an honest answer anywhere.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.