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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:22:27+00:00 2026-06-11T15:22:27+00:00

I have a codeigniter app and in one of my views, i have an

  • 0

I have a codeigniter app and in one of my views, i have an ajax call to an API that returns json data. Once i get the data, I loop through it and append records to an existing table.
There are two ways to run this ajax call. One is to request “all” data, the other is to filter by location.
Both ways return data, but when Im trying to loop through the filtered data set, the ajax is failing.

Here’s the code that loops through the record set:

if (JSONdata.length != 0) 
{
        //create a heading row and attach it to the existing table.
        var heading = $('<tr id="tblheading" naming="tblheading">').appendTo($('#switchrecords'));
        heading.append($('<td>').append().text('Name'));
        heading.append($('<td>').append().text('Object ID'));

        //loop through each JSONdata item in the array and append another row to the switchrecords table.
        $.each(JSONdata, function(i, objswitch) {                           
            console.log('objectid is:'.objswitch.id);
            console.log(objswitch.id);
            var row = $('<tr>').appendTo($('#switchrecords'));
            row.append($('<td>').append($('<a href='+ BASEPATH + 'index.php/controller/methodname/' + objswitch.id + '>').text(objswitch.name)));
            row.append($('<td>').append(objswitch.id).text(objswitch.id));
});

Here’s what I’ve done so far:

  1. I’ve made sure that both result sets have the same fields, namely “id” and “name”. Mind you, the filtered data set includes more fields than the non filtered result but i don’t think that should matter.

  2. I’ve used console.log to dump both result sets… Here’s a snippet from both. The first one is ALL and the other is filtered.

    [{“name”:”888-12-993-99-1″,”id”:”1″,”dict_value”:”compact”},{“name”:”888-22-SR1-RTR-1″,”id”:”2″,”dict_value”:”compact”},{“name”:”888-21-SR1-SW-1″,”id”:”3″,”dict_value”:”compact”},{“name”:”888-11-SR2-SW-2″,”id”:”4″,”dict_value”:”compact”},….etc

    [{“parent_id”:”2″,”tag_id”:”10″,”Location”:”Building1″,”id”:”7″,”name”:”888-22-228-22-1″,”label”:null,”asset_no”:”1026067″,”objtype_id”:”1503″},{“parent_id”:”2″,”tag_id”:”5″,”Location”:”Building2″,”id”:”6″,”name”:”888-2-263-88-1″,”label”:null,”asset_no”:”1026068″,”objtype_id”:”1503″}, …. etc.

  3. As you can see from the code snippet, I’ve tried to add some debug information to see what’s happening inside the loop. However, I’m getting the following error message on the first console.log() call:

    [17:13:30.675] TypeError: “objectid is:”.objswitch is undefined

I’m not really too sure how to resolve this. Any suggestions would be appreciated.
I apologize in advance if it’s a silly mistake! I’ve been programming all day and my brain is mush! =)

Thanks in advance for the help.

  • 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-11T15:22:28+00:00Added an answer on June 11, 2026 at 3:22 pm

    Looks like your syntax is wrong for concatenation .. It should be done using a + , I see you are using a .
    Instead of objswitch try using this

    $.each(JSONdata, function(i) {                           
        console.log('objectid is:' +  this.id);
        console.log(this.id);
        var row = $('<tr>').appendTo($('#switchrecords'));
        row.append($('<td>').append($('<a href='+ BASEPATH + 'index.php/switches/getswitchdetails/' + this.id + '>').text(this.name)));
        row.append($('<td>').append(this.id).text(this.id));
    });
    

    Otherwise try using the variable in general

    $.each(JSONdata, function(i) {                           
        console.log('objectid is:'+  JSONdata[i].id);
        console.log(JSONdata[i].id);
        var row = $('<tr>').appendTo($('#switchrecords'));
        row.append($('<td>').append($('<a href='+ BASEPATH + 'index.php/switches/getswitchdetails/' + JSONdata[i].id + '>').text(JSONdata[i].name)));
        row.append($('<td>').append(JSONdata[i].id).text(JSONdata[i].id));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that submits data to a database in a CodeIgniter app
I have a codeigniter app that queryies an api and gets a simplexml object.
I have a CodeIgniter app that works on one server (IIS 6) just fine.
How do I configure a CodeIgniter app so I can have one directory that
I have an Codeigniter app (using version 2.1.0) that is writing a transaction to
I'm using codeIgniter RESTful API (https://github.com/philsturgeon/codeigniter-restserver) that return information (json format) to my android/iphone
I have a small app in codeigniter. There is a form that has 3
I have a view in my codeigniter app that gets an array from the
I have an app (CodeIgniter) that uses the <?=$variable?> syntax instead of <?php echo
I'm working on upgrading a Codeigniter app I have running on 1.7.2 to 2.0.3

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.