setinterval

Memory leak in jQuery AJAX calls

不问归期 提交于 2019-12-19 08:33:51
问题 I've written a little chat-box widget which runs an ajax call every second, to fetch new messages that have been posted. The problem is it's leaking memory, and after only about 15 mins of being open it crashes my browser (Firefox). It's probably me, as I am a relative newbie, and I'm sure I've missed something out or am not unsetting my variables, etc.. var chat = {} chat.fetchMessages = function() { $.ajax({ url: '/chat_ajax.php', type: 'post', data: { method: 'fetch'}, success : function

How do browsers determine what time setInterval should use?

只愿长相守 提交于 2019-12-19 06:54:58
问题 It would seem that in general, browsers will in certain cases modify, even beyond a minimum clamp, the actual time interval that setInterval uses. For instance, I have the following code: function start() { window.setInterval(function() { update(); }, 1); } lastTime = new Date; numFrames = 0; lastFrames = 0; function update() { numFrames++; if (new Date - lastTime >= 1000) { lastFrames = numFrames; numFrames = 0; lastTime = new Date; } } Here, lastFrames will give us the number of frames over

Node.js setInterval() stops executing after 25 days

拟墨画扇 提交于 2019-12-18 16:45:36
问题 In my Node.js application, I use setInterval() to run a specific function every 1 hour. The function is executed properly for about 25 days, then the timer stops firing. 25 days seems awfully close to Node.js's TIMEOUT_MAX (2^31 milliseconds ≈ 25 days), but I don't really see why setInterval() should stop executing after that time. Update: I think this may have been caused by the following bug in Node.js: setInterval callback function unexpected halt #22149 回答1: It seems the bug (#22149) has

Javascript how to clear interval after specific time

蓝咒 提交于 2019-12-18 12:36:51
问题 setInterval("FunctionA()", 1000); Now how do I clear this interval after exactly 5 seconds so that I can achieve - var i = setInterval("FunctionA()", 1000); (After 5 seconds) clearInterval(i); 回答1: You can do this using setTimeout function: var i = setInterval(FunctionA ,1000); setTimeout(function( ) { clearInterval( i ); }, 5000); 回答2: Using setTimeout to clearInterval is not an ideal solution. It will work, but it will fire your setTimeout on each interval. This is ok if you're only

Javascript setInterval clearInterval Simple Example Not Working Explained?

自古美人都是妖i 提交于 2019-12-18 07:08:27
问题 I have a very simple JS setInterval and clearInterval example that doesn't work. There has got to be an underlying reason why it does not work and I would like to know why that is: var automessage; function turnON() //executed by onclick event A { var automessage = setInterval(function(){ something() }, 2000); } function turnOff() //executed by onclick event B { clearInterval(automessage); } function something() { //pulls instant messages } In this example, an end-user clicks a button to

Difference between arguments in setInterval calls

时光毁灭记忆、已成空白 提交于 2019-12-18 05:12:33
问题 What's the difference between these setInterval calls and which ones should be used? setInterval("myFunction()",1000) setInterval("myFunction",1000) setInterval(myFunction(),1000) setInterval(myFunction,1000) My guess is that JS uses eval() on the first two (strings) and calls the latter two directly. Also, I don't understand the difference between the calls with and without parentheses. The ones with parentheses call it directly and then periodically call its return value? 回答1: Correct; the

setInterval doesn't seem to like () in the function it invokes. Why?

本秂侑毒 提交于 2019-12-17 16:53:13
问题 When I execute the following, incidentController gets called after 10 seconds and continues to execute with no problems every 10 seconds: // This works fine in nodejs v0.11.13 setInterval(incidentController, 10 * 1000); function incidentController () { console.log ('executed'); } However, this executes immediately and throws the following error on the second iteration: //This doesn't. The parens which wrap (123) cause the error. setInterval(incidentController(123), 10 * 1000); function

How do I correctly use setInterval and clearInterval to switch between two different functions?

Deadly 提交于 2019-12-17 09:44:07
问题 For practice I am trying to display a number that increments from 0 - 9, then decrements from 9 - 0, and infinitely repeats. The code that I have so far seems to be close, but upon the second iteration the setInterval calls of my 2 respective functions countUp and countDown seem to be conflicting with each other, as the numbers displayed are not counting in the intended order... and then the browser crashes. Here is my code: <!DOCTYPE html> <html> <head> <title>Algorithm Test</title> </head>

setInterval() only running function once

被刻印的时光 ゝ 提交于 2019-12-17 07:39:28
问题 I want to periodically query a PHP script for new messages. To do so, I'm using the setInterval() function and AJAX. $(document).ready(function(){ var queryInterval = 1000; /* How fast we query for new messages */ setInterval(getMessages(), queryInterval); function getMessages() { console.log("tick"); } }); However, when I look at the Javascript console, I'm only seeing "tick" once. I've made sure that the console doesn't ignore any more logs of the same strings, so if the code was working

setInterval() behaviour with 0 milliseconds in JavaScript

故事扮演 提交于 2019-12-17 05:07:34
问题 In my application I found some JavaScript code that is using setInterval with 0 milliseconds, like so: self.setInterval("myFunction()",0); Obviously, this does not seem like a good idea to me. Can anyone tell me what will be the behaviour of setInterval here? ("myFunction" makes an AJAX call to the server) I am asking this because I am having an irregular behaviour in my application. 90% of the times, the application behaves correctly and exactly one call to the server is made. However