3

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.