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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:14:28+00:00 2026-06-07T04:14:28+00:00

From within my scrip.js file, I’m using jquery $.post function to post some data

  • 0

From within my scrip.js file, I’m using jquery $.post function to post some data (Actually as of right now I’m just trying get my call back to work so I can read some data).

 $('document').ready(function(){

    $.post("index.php/main/showData", 
     function(data){
        console.log(data);
        for (var name in data){
            alert(name);
        }
     }, "json");
});

I’m using codeigniter to access to data the data from mysql:

class Main extends CI_Controller
{
    function showData()
{
    $this->load->model('ajax');
    $array = array($this->ajax->getRecArray());

    // $this->index();
    echo json_encode($array);
}

My model

class Ajax extends CI_Model
{
    function getRecArray()
{
    $query = $this->db->query("SELECT * FROM record_table WHERE id = 1");
    $row = $query->result();
    return $row;
}
}

When I console.log(data) I get:

[[Object { id="1", name="scott"}]]

My question is, How do I access the individual properties or objects from with script.js?
For example, how do I access the value of name in that Object array?

  • 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-07T04:14:29+00:00Added an answer on June 7, 2026 at 4:14 am
     $('document').ready(function(){
    
        $.post("index.php/main/showData", 
         function(data){
            console.log(data);
            for (var name in data[0][0]){
                alert(data[0][0][name]);
            }
         }, "json");
    });
    

    That should do it.

    When you iterate over an object using for .. in, the specified variable doesn’t contain the data, but the string of the member name. In JS you can access object members by the syntax data.member, or data[“member”], and you will want to use the later in this case since you have the string.

    Additionally in this specific case the data is an object inside an array which is inside an array, here is the returned data broken down by levels:

    [
        [
            Object { 
                id="1", 
                name="scott"
            }
        ]
    ]
    

    Hence why you need the syntax data[0][0][name]; this should be easy to fix in the PHP counter part.

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

Sidebar

Related Questions

How can I just call a js function from within an html file, with
I made a Powershell function just now and saved it to a ps1 file.
From within a BPL, is it possible to get its own file name? e.g.
I have a config file that contains the following line: pre_args='$REGION','xyz',3 Using perl from
I'd like to print nicely-formatted data frames to paper, ideally from within a script.
I know I can redirect awk's print output to another file from within a
I need to pull some BLOB data from a SQL Server 2005 database and
Assuming that it is possible to compress a file from within an NSIS script,
From within a python script (main.py), I am using the subprocess module to run
How do you open a unicode named file (with spaces ) from within a

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.