私はいつもjsonファイルから最後の値を取得し、5秒ごとにフェードします。私は何をすべきなので、jsonの各価値が現れて消えますか? :(jqueryでajaxを使用して適切なループを行うことができません
$.ajax({
type:'GET',
url: root + '/posts/1/comments'
}).then(function(data){
$.each(data,function(i, content) {
$('#news').html('<h3>'+ content.name + '</h3><p>' + content.name +'</p>)
.fadeIn().delay(5000).fadeOut('slow');
});
});
});
コンテンツを上書きするのではなく '$( '#news')'に追加しますか? https://api.jquery.com/append/ –
しかし、私はそれを上書きしたい – mrnvdvmv
これを修正してdelay()の代わりにsetTimeout()を使うと、もっと柔軟になります。 –