我有以下jQuery.each()
3輸出,我想回波(append
),他們的每一個在一個標籤li
。
像:
這是輸出$。每():how
& hello
& hi
我想這一點:
<ol>
<li>
<a href="">how</a>
</li>
<li>
<a href="">hello</a>
</li>
<li>
<a href="">hi</a>
</li>
</ol>
但下面的jQuery代碼附加在所有3次一個李,因爲:(我不想要這個)
<ol>
<li>
<a href="">howhellohi</a>
</li>
<li>
<a href="">howhellohi</a>
</li>
<li>
<a href="">howhellohi</a>
</li>
</ol>
這是我的jQuery代碼:
$.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);
}
});
這是我在jQuery代碼響應:
{
"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"
}]
}
如何解決這個問題?
什麼是你的respond.data? – genesis
請參閱我的更新 –