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 a开发者_如何学Cnd 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.
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.
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)
精彩评论