So, I have the original AJAX function:
dataType: 'json',
data : { action: something , id: id},
success: function(data) {
var my_title= data.title; // values: "post1,post2,post3"
var my_name = data.name; // values: "steve,mike,sean"
var my_html ='<div class="'+ my_title +'">'+ my_name +'</div>'
jQuery('.my_class').append(my_html);
}
So, I have two variables (my_titles
and my_name
) each with 3 values (n
number values).
Then, I want to use these individual values for my_html
variable and append them in the .my_class
.
The result will be as follow:
<div class="my_class">
<div class="post1">Steve</div>
<div class="post2">mike</div>
<div class="post3">sean</div>
</div>
So, I tried to edit my AJAX function as below:
dataType: 'json',
data : { action: something , id: id},
success: function(data) {
jQuery.each(data,function (i,n){
var my_title= n.title;
var my_name = n.name;
alert("Title:" + my_title);
});
}
I am getting undefined
as the result.
Any help? thanks!