写真を表示するためのページがあり、ユーザーはそれにコメントを送信でき
ます そのページで 30 秒ごとに ajax を使用して新しいコメントを読み込むための js ファイル名 (ajax.js) を
書き込みます。ユーザーは、すべてのコメントコメントの近くにある削除アイコンをクリックして、非表示にして
コードを削除しますfeed.js :
$('a[cm-del]').click(function () {
var cmid = $(this).attr('cm-del');
var typeid = $(this).attr('data-type');
$('li[last-id=' + cmid + ']').effect('pulsate');
$('li[last-id=' + cmid + ']').hide(300);
$.post('/post/comment.php', {
cmdelete: cmid,
type: typeid
}, function () {});
});
codes ajax.js:
function getmorecmphoto() {
$('li[data-hiv]').hide();
var lastid = $('li[last-id]:last').attr('last-id');
if (lastid === '') {
var lastid = 0;
}
var oldcm = $('div[comments-id]').html();
var photoid = $('div[comments-id]').attr('comments-id');
$.post('/post/photo.php', {
lastid: lastid,
photoid: photoid
}, function (getlastcmphoto) {
$('div[comments-id]').html(oldcm + getlastcmphoto);
});
}
setInterval(getmorecmphoto, 25000);
初めてユーザーがこのページを開くと、最後の10件のコメントがロードされ
、すべてが正常に機能します
が、25〜30秒後に新しいコメントがajaxでロードされると、feed.jsが新しいコメントに対して機能しませんか?
これについて私は何をしなければなりませんか?
新しいコメントが読み込まれるたびにfeed.jsをロードしますが、10分でユーザーが約20のfeed.jsをロードするのは悪いことです!
他にできることはありますか?
ありがとうございました