I have 3 output in following jQuery.each(), i want echo(append) each a of they in one tag li.
Like:
This is output $.each(): how & hello & hi
I want this:
<ol>
<li>
<a href="">how</a>
</li>
<li>
<a href="">hello</a>
</li>
<li>
<a href="">hi</a>
</li>
</ol>
But following jquery code append all 3 times in the a li, as:(i not want this)
<ol>
<li>
<a href="">howhellohi</a>
</li>
<li>
<a href="">howhellohi</a>
</li>
<li>
<a href="">howhellohi</a>
</li>
</ol>
This is my jquery code:
$.ajax({
type: "POST",
dataType: "json",
url: 'get_residence',
data: dataString_h,
cache: false,
success: function (respond) {
$.each(respond.data, function (index, value) {
$('ol li').append('<a href="" class="tool_tip" title="ok">' + value.name[index] + '</a>');
});
},
"error": function (x, y, z) {
alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
}
});
This is my respond in jquery code:
{
"data": [{
"name": "how",
"star_type": "5-hotel",
"site": "www.sasaas.assa",
"service": ["shalo", "jikh", "gjhd", "saed", "saff", "fcds"],
"address": "chara bia paeen"
}, {
"name": "hello",
"star_type": "4-motel",
"site": "www.sasasa.asas",
"service": ["koko", "sili", "solo", "lilo"],
"address": "haminja kilo nab"
}, {
"name": "hi",
"star_type": "3-apparteman",
"site": "www.saassaas.aas",
"service": ["tv", "wan", "hamam", "kolas"],
"address": "ok"
}]
}
How can fix it?
I think this is the logic you’re after:
This will add the data to the proper list item, not the same data to all list items.