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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:25:36+00:00 2026-06-16T23:25:36+00:00

I have been working on a CodeIgniter project and hav run into an issue

  • 0

I have been working on a CodeIgniter project and hav run into an issue with using ajax to return the data from my controller.

Controller:

function outputAjax()
    {
        $this->load->model('my_model');
        $data['results'] = $this->site_model->getInfo();
        $this->output->set_output(json_encode($data));
    }

Model:

function getInfo()
{
    $this->db->order_by('PubDate','DESC');
    $query = $this->db->get('Articles', 50);

        return $query->result();
}

Ajax function in View:

<div id="article-area">
    <p>Hey this is where the ajax call should output!</p>

</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" language="Javascript">
 jQuery(document).ready(function(){     
      $.ajax({
url: 'http://localhost/project/index.php/my_controller/outputAjax',
dataType:'json',
success: function(data) {
    $.each(data, function(index,item){
        $("#article-area").append('<div><b>' + item.id + '</b></div><hr />');

    });
}
      });

});

I can output the data fine using PHP foreach loop but now I am trying to convert that into using ajax. If I am correct, the data being output is an array of objects.
Each ‘object’ contains 6 or so fields of data such as: id, title, url, PubDate, Source.

I am fairly new to using ajax for anything but in my attempt to debug the issue, using Chrome inspect and checking ‘Network’ I can see the ajax call and in the response tab: all of the data I need is shown here in this way:

{"results":[{"id":"1","Source":"My Source","Title":"My Title". . . .

Since the data is shown in the response but either nothing shows up on the page or if I change the ajax call I can get it to output UNDEFINED.

The final result I am looking to achieve is about 10 or so divs on the page with data from the ajax call. Which brings up my side question as well…

My model returns 50 rows of data from the db. I am currently passing all of it to the ajax function in json format. I will only be using 10 rows of that data initially and then use the rest of the rows over a determined amount of time on that page. Is it best to continue to output all 50 rows to the ajax call initially and then use it as needed, or limit the data to only what will be used initially from the model?

I have ran through a few ajax tutorials with CI but, all of them are using a POST and I have yet to find one that is running on document.ready and without user interaction. I also noticed there must be a few various ways to output the data. I have seen the use of .append() .after() and .value() used in this way, none seemed to work for my particular case though…

Thanks 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-16T23:25:37+00:00Added an answer on June 16, 2026 at 11:25 pm

    If your data was simply an array, your code would work. However your data array is contained in an results which is property of an object.

    Change each to:

    $.each(data.results, function(index,item){...
    

    Or simply send the array without putting it into the php results array

    $data = $this->site_model->getInfo();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a home project using CodeIgniter Reactor, and have come to
I have been working on a project that uses Backbone.js router and all data
I have been working an application using PHP & MySql on Codeigniter framework. It
I have been working on a relational data base with Codeigniter and found out
I have been working on a project in C# (.net4). Project pretty much allows
I have been working on a project on and off, but I haven't touched
I have been working on a huge ETL project with 150+ tables and during
I've been working on a web app using the CodeIgniter framework and I am
I have been working on a web development library (for the CodeIgniter framework) that
I come from a Codeigniter MVC background that we've been working with for some

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.