Try:

$.ajax({
    url: "<?php echo site_url('demo/getPhotos/'); ?>",
    type: 'POST',
    data: form_data,
    dataType:"json",
    success: function(data) {
        alert(data[0]);
   }

On the PHP side, you'll be wanting to print:

print json_encode($photos);

Another thing you might try in order to better encapsulate your code, and as an example of further JSON gooodness, would be:

print json_encode(array("photolist"=>$photos,"photo_owner"=>"Me!"));

Then on the server, you'd access these with:

data.photolist[0]; //First photo
data.photo_owner;  //The owner of the photo set
Answer from Richard on Stack Overflow
Discussions

pass php array to javascript using ajax - Stack Overflow
I try to get array from sql server using php , and parsing these array to javascript using ajax. However , I have tried many solution by google , I can't get the array. This is my php code: More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 22, 2017
javascript - Pass php array to Ajax variable - Stack Overflow
i need to pass an array variable to Ajax request $_POST['komment'... More on stackoverflow.com
๐ŸŒ stackoverflow.com
October 30, 2017
How to pass an array of strings from PHP to Javascript using $.ajax()? - Stack Overflow
I have a PHP script that retrieves names (strings) from database. I would like to pass this array to Javascript using $.ajax(). I cannot understand how should I encode the array in PHP and then dec... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Passing array through AJAX from php to javascript - Stack Overflow
I need to get an array generated from a script php. I have Latitude and Longitude for each user in a database. I take the values from the db with this code (file.php): $query = "SELECT Latitude, More on stackoverflow.com
๐ŸŒ stackoverflow.com
January 23, 2013
๐ŸŒ
SitePoint
sitepoint.com โ€บ javascript
How to pass an array from javascript ajax function into into php script? - JavaScript - SitePoint Forums | Web Development & Design Community
July 31, 2020 - I have an ajax function that connects to a php file. Iโ€™m trying to pass arguments (โ€˜tax_queryโ€™) collected on the page to a query running on php. How can I create an array (or maybe just a string) in javascript and pass that as an argument to the function inside php.
๐ŸŒ
Code Boxx
code-boxx.com โ€บ home โ€บ 5 ways to pass php variables & arrays to javascript
5 Ways To Pass PHP Variables & Arrays To Javascript
October 19, 2023 - Welcome to a tutorial on how to ... together? A quick and easy way to pass a variable from PHP to Javascript is to use the short echo tag....
๐ŸŒ
Quora
quora.com โ€บ How-do-I-pass-a-PHP-array-to-Ajax-jQuery
How to pass a PHP array to Ajax jQuery - Quora
Answer (1 of 3): In order to send PHP array as a response of AJAX request, you need to encode that array first using json_encode() function. [code]$a = [โ€œstring1โ€,โ€string2โ€]; echo json_encode($a); [/code]Then you can use this data by parsing the JSON into native javascript object using ...
๐ŸŒ
CodeProject
codeproject.com โ€บ Questions โ€บ 5283869 โ€บ Pass-javascript-array-to-PHP-using-AJAX
Pass javascript array to PHP using AJAX - CodeProject
October 28, 2020 - Free source code and tutorials for Software developers and Architects.; Updated: 30 Oct 2020
๐ŸŒ
Hhutzler
hhutzler.de โ€บ blog โ€บ php-pass-an-array-to-javascript-using-ajax-jquery-and-phps-json_encode
Pass an Array to Javascript using AJAX (jquery ) and PHP's ...
do_action(Array) #16 /customers/9/0/5/hhutzler.de/httpd.www/blog/wp-includes/general-template.php(3015): do_action('wp_head') #17 /customers/9/0/5/hhutzler.de/httpd.www/blog/wp-content/themes/twentyfifteen/header.php(21): wp_head() #18 /customers/9/0/5/hhutzler.de/httpd.www/blog/wp-include...
Find elsewhere
๐ŸŒ
Makitweb
makitweb.com โ€บ home โ€บ ajax โ€บ how to send javascript array to the ajax using jquery and php
How to Send JavaScript Array to the AJAX using jQuery and PHP - Makitweb
December 21, 2023 - To handle AJAX requests, create a file named getData.php. In this file, retrieve the values from the $_POST. Check if the $_POST['lang'] variable contains the string โ€œjQueryโ€. If it does, convert the array into a string using the implode() ...
๐ŸŒ
SourceBae
sourcebae.com โ€บ home โ€บ how can i return an array from php to an ajax call?
How Can I Return an Array from PHP to an Ajax Call? - SourceBae
August 21, 2025 - To return the array from PHP to the Ajax call, you can use the json_encode function. This function converts a PHP variable into a JSON string, which can be easily processed by JavaScript.
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ community โ€บ pass-javascript-array-to-php
pass javascript array to php (Example) | Treehouse Community
May 7, 2014 - From the moment i type 2 characters in the textfield the autocomplete function shows names from the mysql database and if i select a name press the 'Add' button it shows them in a listview and adds the value to the Array 'list'. Now i want to use the values inside the array in the php file data.php so i can run some queries on my database with these values. I found all kinds of solutions on stackoverflow using ajax, json but i can't get it to work.
๐ŸŒ
YouTube
youtube.com โ€บ makitweb
How to Send JavaScript Array to the AJAX using jQuery and PHP - YouTube
This video shows how you can send JavaScript Array as data in the AJAX request and handle it with jQuery and PHP.Read tutorial and download code - https://m...
Published: December 22, 2018
Views: 6K