所以我想獲得一系列的json結果,以使用innerHTML呈現在div標記內。基本getJSON in for循環與innerHTML問題
<script>
$(document).ready(function() {
var html2 = '';
var thread_id = '';
var created_thread_ids = new Array(123123, 12312312, 1231222);
for (var i in created_thread_ids)
{
thread_id = created_thread_ids[i];
$.getJSON(ravenUrl + '/docs/threads/' + thread_id, function(thread){
html2 += '<div class="result">' + thread.Title + thread_id + '</div>';
document.getElementById("showit").innerHTML = html2;
});
}
});
</script>
<div id="showit"></div>
我的問題是,可變thread.Title完美的作品,但變量的thread_id只有當它的url和找到正確的網址,但第二次它顯示了相同的ID後,每工作在第一時間線。就像這樣:
<div id="showit">
<div class="result">This is the first title123123</div>
<div class="result">This is the second title123123</div>
<div class="result">This is the third title123123</div>
</div>
非常感謝你:) – Niko