因此,我试图获得一系列 json 结果,以使用 innerHTML 在 div 标记中呈现自身。
<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 并找到正确的 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>