Can I get an array with jQuery $ .post?

I am using jquery $ .post to dynamically retrieve information from a database. This works fine if I need one element, I would like to save each column as an array and pass the entire array. I have an array, but I have problems returning it to javascript, so I can use it.

Since the array will contain text with commas, I cannot use implode to create a comma separated string.

+3
source share
2 answers

Try using json, if you use php json_encode in a server-side array, then the echo of the jquery encoded array will perceive it as a json object.

+1

"json" :

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

}, "json");

.each

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

});

:

data['key']

. , , , /your/page, JSON ( PHP . json_encode)

0

Source: https://habr.com/ru/post/1762391/


All Articles