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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:53:29+00:00 2026-06-13T10:53:29+00:00

I have a PHP script that makes query to DB and returns the result

  • 0

I have a PHP script that makes query to DB and returns the result as JSON data. This file contains some Codeigniter specific functions.

This functions recieve id and returns back to the JS code some data from a table.

public function get_l($id){
//$id is not empty variable
$this->db->where('id',$id);
$q=$this->db->get('news');

$res = $q->result_array();

$this->output->set_header("HTTP/1.0 200 OK");
$this->output->set_header("HTTP/1.1 200 OK");
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
$this->output->set_header("Content-Type: application/json; charset=utf-8");
$this->output->set_header("Pragma: no-cache");

$out = json_encode($res);
$this->output->set_output($out);
}

And then I need to process that JSON with the next JS code:

function getContent(id){
  $.post('/admin_ajax/news/get',
  {
    id: id

  },
  function(result)
  {
    alert(result+"\n"+result.length);//this will output [object Object] 1
    for (var key in result)
    {
      alert(key+':'+result[key]); //and this 0:[object Object]
    }
    alert(result.title); //here we are getting undefined
  },
  'json'
);

I am not receiving errors or warnings in console. And in the firebug I see what was returned from the server.

HTTP headers:

Server  nginx/1.1.19
Date    Fri, 26 Oct 2012 11:59:12 GMT
Content-Type    application/json; charset=utf-8
Content-Length  85
Connection  keep-alive
X-Powered-By    PHP/5.3.10-1ubuntu3.4
Cache-Control   post-check=0, pre-check=0
Pragma  no-cache

And response:

[{"id":"5","title":"test","alias":"test","content":"tes","date":"123","type":"test"}]

JSON:

alias  "test"

content "tes"

date  "123"

id "5"

title "test"

type "test"

I found a similar question here but it wasn’t helpful.

  • 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-13T10:53:30+00:00Added an answer on June 13, 2026 at 10:53 am

    It seems like the response you are getting is actually an array with one element (the json object).

    Try using result[0], like so:

    ....
    function(result)
      {
        alert(result[0]+"\n"+result[0].length);//this will output [object Object] 1
        for (var key in result[0])
        {
          alert(key+':'+result[0][key]); //and this 0:[object Object]
        }
        alert(result[0].title); //here we are getting undefined
      }
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php script that watches for the newest json file in a
I have a PHP script ( script A ) that makes a query to
I have a php script that inserts data from an Android app into a
I have a PHP script that executes a .bat file using system(cmd /c C:\dir\file.bat);
I have a php script that makes a random token (A-Z, a-z, 0-9): function
I hope that title makes sense.... Basically I created PHP script to take data
I have written a php script that returns an arbitrary number of specific ids
I have a Google Instant style jQuery search script that queries a PHP file
I have a php script that loads data from a database. The table I
Ok, So I have a external php script that get data from a DB

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.