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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:06:32+00:00 2026-05-20T14:06:32+00:00

How does one go about returning a json object in this case(messages) to a

  • 0

How does one go about returning a json object in this case(messages) to a view(admincp_index).
The method below works fine but I would really like to spice it up with some animations

Regards, Phil

/* AdmincontrolPanel */
function index()
{
    $data['messages'] = $this->session->flashdata('messages');
    $data['content'] = 'admincp/admincp_index';
    $this->load->view('backend/template', $data);
}


 function applicant()
 {
      $id = $this->input->post('id');

      if($this->input->post('accept'))
      {
            if($this->admincpModel->accept_applicant($id) == TRUE)
            {
                 $this->session->set_flashdata('messages', '<div class="ok">Applicant Added!</div>');
                 redirect('admincp');
            }            
 }

/* admincp_index */

if($messages){
    // echo messages
}
  • 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-05-20T14:06:33+00:00Added an answer on May 20, 2026 at 2:06 pm

    There are three things that need to be kept in mind:

    1. The browser may cache the JSON response, so it’s a good idea to append a time-stamp to the end of the URL to keep the data coming in fresh. (This is true of the GET method, not necessarily so with POST though).

    2. The content type of the JSON response needs to be “application/json” or “text/javascript“.

    3. The json_encode function was included with PHP 5.2, so older environments may not be able to use it, and you’ll have to either get the module installed or write your own encoding class.

    I’m doing some work on a server running PHP 5.1.6, and I don’t need to serialize any complex types, so I’ve found the technique shown below to work fine. I’m using a simple “JSON view” which sets the correct content type in the response header, and emits a JSON string which was manually concatenated in the controller.

    Phil, jQuery effects/animations could make use of the returned JSON data in the success callback function. In the example below I’m just showing message in an alert box.

    Client-side Code:

    // the jQuery POST URL includes a time stamp
    var now = new Date();
    $.ajax({
        type: "POST",
        url: "page/post/" + now.valueOf().toString(),
        data: {},
        dataType: "json",
        success: function (result) {
            alert(result.message);
        }
    });
    

    Controller (/application/controllers/page.php):

    class Page extends CI_Controller {
    
        function __construct()
        {
            parent::__construct();
        }
    
        function index()
        {
        }
    
        function post($TimeStamp)
        {
            /* process request... $Timestamp may or may not be used here. */
    
            $data['json'] = '{"message":"The post was handled successfully."}';
            $this->load->view('json_view', $data);
        }
    }
    

    View (/application/views/json_view.php):

    <?php
    $this->output->set_header('Content-Type: application/json; charset=utf-8');
    echo $json;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am getting this error does some one knows about it??? 2009-07-08 18:42:36.778 FlashCards[1297:20b]
How does one go about catching exceptions from using controls in markup? For example,
How does one go about properly analyzing the requirements of a client in terms
I was curious as to how does one go about finding undocumented APIs in
In jQuery, how does one go about finding all the 'unchecked' checked boxes. $(':checkbox:checked');
Does any one know about opensource network monitor tool for BlackBerry ?
Perhaps I am missing something but how does one go about retrieving the xml
does one perform better over the other in terms of indexing/quering etc ? e.g.
How does one wait until all of the Javascript is loaded before curling a
How does one implement a multithreaded single process model in linux fedora under c

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.