Reputation: 2705
I send data from php script to my Jquery function. data are as:
[[{"t":"Knjige, revije, stripi"},{"t":"Vse ostalo"},...']]
Jquery code:
function newFunction(data){
jQuery.each(data, function(index, tag) {
$('#list').append('<li>' + tag + '</li>');
});
}
the problem is I get list as:
[
[
"
A
v
d
i
o
"
,
"
O
s
t
a
l
i
"
,
everything in own line. What am I doing wrong?
Upvotes: 0
Views: 37
Reputation: 4383
Your data variable is still a string, so each() is going through each character. You have to parse it first.
function newFunction(data){
data = JSON.parse(data);
jQuery.each(data, function(index, tag) {
$('#list').append('<li>' + tag + '</li>');
});
}
Upvotes: 1