Learn how to a build a cloud-first strategyRegister Now


PHP to return an array to SAJAX, having trouble

Posted on 2006-03-27
Medium Priority
Last Modified: 2008-01-09
I have sajax working, im new to it.

I have a PHP function:

function get_table2_data(){
      return array('achievements', 'second');


then my javascript function that handles the data does this:

function do_table2_update_cb(table_arr) {
      for (j = 0; j < table_arr.length; j++)
              var table2_el = document.getElementById('table2');
              table2_el.options[table2_el.options.length] = new Option(table_arr[j], table_arr[j]);

and that first alert is just showing 'A' as if table_arr is just a string with a value of 'Array'

Any ideas how to get PHP to return a javascript array

Question by:antum
1 Comment

Accepted Solution

malaiac earned 2000 total points
ID: 16309312

try this:

function get_table2_data(){
     return implode(",",array('achievements', 'second'));

function do_table2_update_cb(table_arr) {
     //table_arr is now a csv string
     //now we do an explode after comma
     var arrSplitString=table_arr.split(",");

     for (j = 0; j < arrSplitString.length; j++)
            var table2_el = document.getElementById('table2');
            table2_el.options[table2_el.options.length] = new Option(arrSplitString[j], arrSplitString[j]);

in this way you do not send arrays, you send strings

hope it helped

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question