Javascript 停止间隔一次console.log显示未定义
我已经创建了一个interval函数来反复运行我的函数,在用新数据刷新dom之后,在某个时刻,my console.log将显示undefined。如何在my console.log状态未定义时捕获或停止间隔。我们是否可以使用一个函数来捕获当使用未定义消息触发console.log时的情况 Console.logJavascript 停止间隔一次console.log显示未定义,javascript,jquery,d3.js,Javascript,Jquery,D3.js,我已经创建了一个interval函数来反复运行我的函数,在用新数据刷新dom之后,在某个时刻,my console.log将显示undefined。如何在my console.log状态未定义时捕获或停止间隔。我们是否可以使用一个函数来捕获当使用未定义消息触发console.log时的情况 Console.log VM64:56 19 VM64:56 18 VM64:56 17 VM64:56 16 VM64:56
VM64:56 19
VM64:56 18
VM64:56 17
VM64:56 16
VM64:56 15
VM64:56 14
arc_all.js?v=5.1.3.0-1570239956:18 undefined display format making Product Design Risk NaN
arc_all.js?v=5.1.3.0-1570239956:18 undefined display format making <span data-dim="16" data-dimidx="2" class="crosstab-expand"> <i class="fa fa-plus-square-o"></i></span> NaN
arc_all.js?v=5.1.3.0-1570239956:18 undefined display format making Anti-Competitive Conduct Risk NaN
VM64:56 13
...
VM64:56 0
VM64:56 19
VM64:56 18
VM64:56 17
VM64:56 16
VM64:56 15
VM64:56 14
arc_all.js?v=5.1.3.0-1570239956:18未定义的显示格式导致产品设计风险
arc_all.js?v=5.1.3.0-1570239956:18未定义的显示格式
arc_all.js?v=5.1.3.0-1570239956:18未定义显示格式导致反竞争行为风险
VM64:56 13
...
VM64:56 0
为了进一步阐述我的函数,我创建了这个函数,这个函数。函数工作正常,我不确定应该采取什么方法在console.log上获取未定义的消息
function auto_refresh(start_count) {
window.repeat = setInterval(function(){
start_count = start_count - 1;
console.log(start_count)
const request = $.ajax({
async : true,
success : function(){
setTimeout(customStyle(), 100)
},
});
if (start_count <= 0) {
//Will clear interval when timer is 0
window.clearInterval(window.repeat);
console.log('Inside the call function to be removed ' + window.repeat);
}
}, 1000);
}
// // Call auto_refresh function and set 1 - 10 , e.g 10 will run interval for 10 seconds and => stop function ,
// // Bigger datasets , set to 30 - 150 or which is preferred
auto_refresh(20)
函数自动刷新(开始计数){
window.repeat=setInterval(函数(){
开始计数=开始计数-1;
console.log(开始计数)
const request=$.ajax({
async:true,
成功:函数(){
setTimeout(customStyle(),100)
},
});
如果(启动计数停止功能,
////更大的数据集,设置为30-150或首选哪个
自动刷新(20)
setInterval
返回一个值,该值可以传递给clearInterval
以停止该间隔。您可以检查window.repeat值是否未定义,然后执行某些操作。例如,我在未定义时启动了调试器:
if (window.repeat === undefined) {
debugger;
} else {
console.log('Inside the call function to be removed ' + window.repeat);
}