私はこのコードを持っていますが、問題は、ループを停止してテキスト「Done!」を置き換えたいということです。これは、「textnew」文字列を含む sms-loader.php スクリプトから取得されます。問題は、ループがもう一度発生するため、div.checkstatus フィールドのテキストが呼び出し元の php スクリプトに再び置き換えられることです。
奇妙なことに、ログ メッセージが表示され、再び新しい (そして最終的な) 要求が返されますが、スクリプトでは順序が逆になっています (最初に停止してから text() を置き換える)。なぜこれが起こっているのかを理解する必要があります。
$(document).ready(function() {
var interval = "";
$('.checkstatus').each(function(){
var msgid = $(this).data('msg')
$this = $(this),
hid = $this.data('history'),
textnew = '<a href="sms-dstatus.php?id='+msgid+'&sid=' +hid+ '&keepThis=true&TB_iframe=true&height=430&width=770" title="Delivery Status" class="thickbox"><img src="../template/icons/supermini/chart_curve.png" alt="status" width="16" height="16" /></a>';
interval = setInterval(function() {
$this.load('../pages/sms-loader.php?id='+msgid);
// stop the loop
if($this.text()=='Done!'){
// stop it
clearInterval(interval);
console.log(textnew);
$this.html(textnew); /// this line is the problem
}
}, 5000); // 5 secs
});
});