views:

61

answers:

2

I using jquery's $.post to pull information from a database dynamically. This works fine if I want one item however, I would like to store each column as an array and pass the whole array over. I have the array but am having issues pulling it back to javascript so I can use it.

Since the array will contain text with commas I can't use implode to create a comma separated string.

+1  A: 

Try using json, if you use php's json_encode on the array on the server side then echo the encoded array jquery will pick it up as a json object.

Obsidian
A: 

You must append the "json" like this:

$.post("/your/page", dict,
 function(data) {
  dosomething();

}, "json");

then you can use the .each for looping

jQuery.each(data, function(i, val) {
 alert(i);
 alert(val);

});

or reference values by keys like this:

data['key']

You need to use an associative array. Also, it is required that the data returned by /your/page is JSON encoded (for PHP see json_encode)

Uku Loskit