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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:42:56+00:00 2026-05-24T20:42:56+00:00

ajax calls below php and expect an array of json to be return. I

  • 0

ajax calls below php and expect an array of json to be return. I think I have the data ready but don’t know how to return them correctly.

$files = array();
foreach($db2_databaselist as $db) {

    $file = new stdClass();
    $file->data = date('Y-m-d--H:i:s',strtotime($db));
    $file->attr = new stdClass();
    $file->attr->rel = "file";
    $file->attr->timestamp = $db.$type[0];

    $files[] = json_encode($file);
}
   echo "<pre>Output = " . print_r($files,TRUE) . "</pre>";
   echo "<BR><BR><BR>";
   print_r($files, TRUE);

where print_r($files,TRUE) gives me

Output = Array
(
    [0] => {"data":"2011-08-07--02:30:05","attr":{"rel":"file","timestamp":"20110807023005w"}}
    [1] => {"data":"2011-07-31--02:30:09","attr":{"rel":"file","timestamp":"20110731023009w"}}
    [2] => {"data":"2011-07-24--02:30:09","attr":{"rel":"file","timestamp":"20110724023009w"}}
)

But print_r($files,TRUE) returns nothing.

How can I get php to return

[
 {"data":"2011-08-07--02:30:05","attr":{"rel":"file","timestamp":"20110807023005w"}},
 {"data":"2011-07-31--02:30:09","attr":{"rel":"file","timestamp":"20110731023009w"}},
    [2] => {"data":"2011-07-24--02:30:09","attr":{"rel":"file","timestamp":"20110724023009w"}}
]
  • 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-24T20:42:57+00:00Added an answer on May 24, 2026 at 8:42 pm

    You don’t need json encode after the loop as things are. You need implode. Your array values are already JSON strings, which means that using json_encode will only escape the strings!

    Instead:

    echo '['.implode(',',$files).']';
    

    OR! You could skip json_encode on this line:

    $files[] = json_encode($file);
    

    And the end of the loop would look like this instead:

        $files[] = $file;
    }
    
    $files = json_encode( $files );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery script as below: $.ajax({ type: GET, url: http://www.site.com/v4/ajax/get_song_info.php, data: ({id
I have an ajax call as below: $.ajax({ type: GET, url: process.php, data: dataString,
I'm making AJAX calls to a server that sometimes return unparseable JSON. The server
I'm kind of new to jquery/ajax calls, I have this code below to pull
I have a jquery.ajax routine that calls a php script. The php script does
As jquery ajax calls makes life really cool without a page refresh... But still
I use jQuery to do AJAX calls. But specialchars like ÆØÅ (danish letter) comes
Is there any limitations on AJAX Calls with ScriptManager to Web Services? I have
I am having problems with jQuery Ajax and PHP I have my php file
I have the code as per below. This retrieves some data to use for

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.