データベース エントリが存在するかどうかを確認する関数を実行しています。
ページの読み込み時に、要素が存在するかどうかを確認し、存在する場合はsetInterval
関数を実行します。そのようです:
if ( $('#encoding').length ) {
console.log("auto_update start");
var update = setInterval(auto_update, 12000);
}
次に、私のauto_update
機能でこれが起こります
function auto_update() {
console.log("auto_update running");
$.ajax({
type: 'POST',
url: ajaxurl,
data: {
action: "dhf_ajax_router",
perform: "dhf_check_status", // the function we want to call
post_id: $('#post_id').val(),
nonce: $('#dhf-video-meta-nonce').val()
},
success: function(response) {
if ( response === "continue" ) {
console.log("still encoding");
} else {
clearInterval(update);
console.log("complete " + response);
}
}
});
}
問題は$('#encoding')
、開始時にページに存在せず、ユーザーが次の範囲内で手動で起動した場合です。
$(document).on("click", ".run_encode", function(){
// doing the necessary stuff here.
if ( response === "sent" ) {
// more stuff
var update = setInterval(auto_update, 12000);
}
}); // end .run_encode
その後、clearInterval(update)
は機能せず、無限ループに陥ります。
理由がわかりません。どちらの場合も名前付きの間隔update
が設定されているのに、2 番目の状況ではクリアが機能しないのはなぜですか?