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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:22:53+00:00 2026-06-18T08:22:53+00:00

I am new to PHP, I have following scenario; On PHP side I have

  • 0

I am new to PHP, I have following scenario;
On PHP side I have a file get_folders.php

<?php
$arr = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/var       z/www/scripts')) as $filename)
{

 array_push($arr,$filename);
}
print (json_encode($arr));
?>

On html side I have

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<script type="text/javascript" src="jquery.js"></script>          
<script type="text/javascript">   

function myFunction()
{
    $.getJSON("get_folders.php", function(data){


   alert("Data Loaded: " + data);

    $('#thetable');
   var html = '';
   for(var i = 0; i < 10 ; i++)
        html += '<tr><td>' + data;
   $('#thetable').append(html);
  });                                      

  }                  
 </script>                                                               
 </head>     
 <button onclick="myFunction()">Try it</button>
 <div>
 <table id="thetable">
 <th>Header 1</th>
 </tr>
 <tr>
 <td></td>
 </tr>
 </table>
 </div>

…….
I can print the array on php side and its all good. But only thing i get in alert is

Data Loaded: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

  • 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-18T08:22:54+00:00Added an answer on June 18, 2026 at 8:22 am

    Firstly, the Javascript alert() function is pretty basic; it can only deal with string input. If you give it an object or an array, it will choke. You’re giving it objects, so it is showing you that fact in the best way it can.

    If you really want to see what the data variable contains, I recommend using the browser’s debugging tools rather than alert(). All modern browsers have a console.log() function, which outputs your debug data to the debugging console rather than an alert box. This will give you much more useful info. Press F12 to get the debugging panel in any browser.

    But my guess is that you aren’t intending to output an arry of SPLFileInfo objects. It looks like you’re probably intending to send an array of filenames.

    The iterators you’re using for the loop produce an SPLFileInfo object, not simply the filename.

    To get just the filename, you would use the getFilename() method, like so:

    foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/var/www/scripts')) as $fileinfo)
    {
        array_push($arr,$fileinfo->getFilename());
    }
    

    This will now generate an array of filenames, which I think is what you want.

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

Sidebar

Related Questions

I am newbie to PHP I have written the following program: $address=array('abc@gmail.com','abc@hotmail.com','def@yahoo.com'); foreach($address as
I have the following .htaccess file: RewriteRule ^s/([a-zA-Z]+) /servers/page.php?name=$1 RewriteRule ^s/([a-zA-Z]+)/new-thread /servers/new-thread.php?name=$1 As you
I am new to PHP and am following a tutorial on YouTube. I have
I have following setup. index.php require_once common.php; ... common.php ... $obj = new MyClass;
I have the following string: $/Mycollection/Branches/Dev/New/php/MySite/src/MySite/somefolder/src/sad.php I need to create regex pattern and take
P.S. I am new to php & webform scripting; Currently I have the following
i have following php file.... mysql_connect(localhost,root,); mysql_select_db(database_name); $sql=mysql_query(select * from members); while($row=mysql_fetch_assoc($sql)) $output[]=$row; print(json_encode($output));
I have a new website. And the following is my scenario: I will send
I'm new to PHP and struggling with a login page. I have the following
I have following php code in a file: $figloc = $_GET['figrl']; try { $image

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.