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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:55:45+00:00 2026-06-03T03:55:45+00:00

I’m following the tutorial here: http://www.jotorres.com/2012/01/using-jquery-and-ajax-with-codeigniter/ For my view, I have: <script type=text/javascript src=<?php

  • 0

I’m following the tutorial here:
http://www.jotorres.com/2012/01/using-jquery-and-ajax-with-codeigniter/

For my view, I have:

<script type="text/javascript" src="<?php echo jquery ?>"></script>

<button type="button" name="getdata" id="getdata">Get Data.</button>

<div id="result_table">

</div>

<script type="text/javascript" language="javascript">
$('#getdata').click(function(){

    $.ajax({
            url: "<?php echo base_url().'users/get_all_users';?>",
            type:'POST',
            dataType: 'json',
            success: function(output_string){
                    $("#result_table").append(output_string);
                } // End of success function of ajax form
            }); // End of ajax call
     });
</script>

The header and footer are predominantly links to other pages on the website but the relevant sections of the header and beginning are:

<!DOCTYPE html>
<!-- Website template by Jeremiah Tantongco, jtantongco@gmail.com -->
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title><?php echo $title ?> </title>
        <link rel="stylesheet" href="<?php echo template ?>" type="text/css" />
        <link rel="stylesheet" href="<?php echo display_elements ?>" type="text/css" />
    </head>

Note: template and display_elements are variables pointing to css files somewhere on the server declared in config/constants

Note: jquery is a variable declared in config/constants that points to the newest jquery file on the server. It is the newest developer version available.

for controller methods:

public function test(){
    $this->renderTemp_noData('users/test', 'Test page');
}

public function get_all_users(){
    $query = $this->db->get('users');

    if($query->num_rows > 0){
        $header = false;
        $output_string = "";
        $output_string .=  "<table border='1'>\n";
        foreach ($query->result() as $row){
            $output_string .= "<tr>\n";
            $output_string .= "<th>{" . $row->uid ."}</th>\n";
            $output_string .= "</tr>\n";
        }
        $output_string .= "</table>\n";

    }
    else{
        $output_string = "There are no results";
    }
    //echo $output_string;
    echo json_encode($output_string);
}

public function renderTemp_noData($page, $title) {
    $data['title'] = $title;
    $accountType = $this->session->userdata('aid');

    switch ($accountType) {
        case 0: 
            $this->load->view('templates/LI_header', $data);
            $this->load->view($page);
            $this->load->view('templates/LI_footer');
            break;
        case 1: 
            $this->load->view('templates/LI_header_role1',$data);
            $this->load->view($page);
            $this->load->view('templates/LI_footer_role1');
            break;          
        case 2: 
            $this->load->view('templates/LI_header_role2',$data);
            $this->load->view($page);
            $this->load->view('templates/LI_footer_role2');
            break;
        case 3: 
            $this->load->view('templates/LI_header_role3',$data);
            $this->load->view($page);
            $this->load->view('templates/LI_footer_role3');
            break;
        default:
            redirect('/sessions/log_in/','refresh');
    }
}

When I go to the page with the Get Data button, I press it and nothing happens. So if anyone knows how to expose the error message that would be great. Also, When I test to see output for get_all_users, this is what I get:

"<table border='1'>\n<tr>\n<th>{1}<\/th>\n<\/tr>\n<tr>\n<th>{2}<\/th>\n<\/tr>\n<tr>\n<th>{3}<\/th>\n<\/tr>\n<tr>\n<th>{4}<\/th>\n<\/tr>\n<tr>\n<th>{5}<\/th>\n<\/tr>\n<tr>\n<th>{6}<\/th>\n<\/tr>\n<tr>\n<th>{7}<\/th>\n<\/tr>\n<tr>\n<th>{8}<\/th>\n<\/tr>\n<tr>\n<th>{9}<\/th>\n<\/tr>\n<tr>\n<th>{10}<\/th>\n<\/tr>\n<tr>\n<th>{12}<\/th>\n<\/tr>\n<tr>\n<th>{13}<\/th>\n<\/tr>\n<tr>\n<th>{14}<\/th>\n<\/tr>\n<tr>\n<th>{15}<\/th>\n<\/tr>\n<tr>\n<th>{16}<\/th>\n<\/tr>\n<tr>\n<th>{17}<\/th>\n<\/tr>\n<tr>\n<th>{18}<\/th>\n<\/tr>\n<\/table>\n"

Is JSON supposed to look this way? My gut says no but this is the first time I’ve ever used JSON, Jquery, and AJAX. Also, The numerical values are correct. Looking at my database, there are only UIDs 1-18 with no 11.

  • 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-03T03:55:46+00:00Added an answer on June 3, 2026 at 3:55 am

    Your get_all_users() function adds HTML to your $output_string, which you are then json_encoding. That’s not quite how JSON works. Replace with:

    public function get_all_users() {
        $this->output->set_content_type('text/javascript; charset=UTF-8');
    
        $query = $this->db->get('users');
        echo json_encode($query->result());
    }
    

    That said, your database calls should live in a model, not your controller.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.