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 8719181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:43:52+00:00 2026-06-13T06:43:52+00:00

I have an index.html file that calls main.php which returns a json object just

  • 0

I have an index.html file that calls main.php which returns a json object just fine.

main.php returns this

{
    "products": [
        {
            "id": "1",
            "txt": "Bar",
            "image": "",
            "page": ""
        },
        {
            "id": "2",
            "txt": "Car",
            "image": "",
            "page": ""
        },
        {
            "id": "3",
            "txt": "Far",
            "image": "",
            "page": ""
        }
    ],
    "success": 1
}

in Java there is json.getJSONArray(TAG_PRODUCTS);

but…. I am using HTML and javascript here…
so in my html file I have the following
how do I pull the products array out of my json returned data?

$.ajax({
    type: 'POST',
    dataType: 'json',
    url: 'http://localhost:8888/HelloWorld/main.php',
    contentType: "application/json; charset=utf-8",
    success: function (data) { 
        var names = data
        $('sa_content').append('<select name="input_4">');
        $.each(data, function(index, element) {

            alert( "index: " + index + ", element.cf_id: " + element );

        });
        $('sa_content').append('</select>');
    },
    error: function(){
        $('#sa_content').append('<li>There was an error loading the feed');
    }
});

When I run the index.html page I get the following alerts

index = products, element =  [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

and

index = success, element =  1

So how do I pull the products array out of the json and iterate through it to get the values of id, txt, image, page?

Thanks in advance for your time.
Dean-O

  • 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-13T06:43:54+00:00Added an answer on June 13, 2026 at 6:43 am

    Try using this as the success function:

    function (data) {
        var products = data.products;
    
        for (var i = 0; i < products.length; i++) {
            var product = products[i];
            alert(product.id + " " + product.txt + " " + product.image + " " + product.page);
        }
    }
    

    It should iterate through all the products and alert you the data.
    Then you can modify the code to suit your needs.

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

Sidebar

Related Questions

I have a PHP script (index.php) that includes an index.html file in a sub-directory
Absolute beginner question: I have a template file index.html that looks like this: ...
I have Javascript function defined in the main index.html file. One part of this
I have an upload script that write a index.html file, I modified it to
I have a template in joomla without index.php I only have index.html, css file,
i am using php 5.2.8 i have index.html, which loads LOAD.PHP from IFRAME. iframe
I have web application which is comprised of an index.html file which includes an
I have activated the IIS package for windows, and, I created an index.html file
I have the following file structure: |- index.html vendor |- jquery.min.js (some libraries) js
Basicily i have a index.html shown below.. <html> <head> <title>UI Test: Main Menu</title> <script

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.