【发布时间】:2016-02-09 14:21:02
【问题描述】:
我有这个 HTML 代码:
<div class="content">
<article class="underline">
<a href="incidente.html"><img id="incidente"
src="img/buraco.jpg" alt="Incidente" /></a>
<h2><a href="basic_markup.html" id="tit"></a></h2>
<p id="desc">Esse buraco na rua Montes Claros já está há 1 ano
trazendo transtornos aos moradores</p><p></p>
<div class="date" id="date"></div>
<img class="tick" alt="não resolvido" src="img/no-tick.png">
<img class="apoio" alt="apoiar" src="img/apoio.png">
</article>
还有这个接收数组的ajax:
$.ajax({
type: "GET",
url: "http://localhost/again/www/index.php",
dataType: "json",
success: function (data) {
var tit = "";
// Loop over each object
for (var $i = 0; $i < data.length; $i++) {
var object = data[$i];
tit+= object.titulo;
}
$('#tit').html(tit);
}
});
</script>
现在,它在相同的 HTML 代码中插入所有内容(当然,因为我没有 foreach),但我想为我收到的每一行(每个“tit”)显示这个 HTML。 ..有人能帮我吗?
【问题讨论】:
-
您想为每个结果生成一个新的文章块吗?
-
@Dontfeedthecode 是的,正是我想要的。为每个结果生成一篇新文章...
-
您能否粘贴一个在您的 $.ajax 函数中返回的 JSON 示例?
-
@Dontfeedthecode 我的 ajax 正在接收这样的 Json 数组:[{"codigo":"32","0":"32","titulo":"Some title here","1 ":"这里有一些标题","descricao":"这是我的描述","2":"这是我的描述","data":"2015-10-29 21:48:13","3" :"2015-10-29 21:48:13"l},{"codigo":"33","0":"33","titulo":这里的标题,"1":这里的标题,"descricao" :description here,"2":description here,"data":"2015-10-30 20:45:46","3":"2015-10-30 20:45:46"}]
-
@Dontfeedthecode 对于每个标题我想生成一篇文章...
标签: javascript html ajax loops foreach