setinterval

Jquery/Ajax call with timer

馋奶兔 提交于 2019-11-26 07:30:16
I have a php page that echos out rows from a database. I want to call it via jquery/ajax every 30 seconds. But I also want to be able to call the page at any time so that if I add a record via the form, once the form submits I want the page via called to ajax to update the results right away. Can anyone point me in the right direction or provide some base code so I can try to figure this out? Still very new to jquery/ajax. treeface If you want to set something on a timer, you can use JavaScript's setTimeout or setInterval methods: setTimeout ( expression, timeout ); setInterval ( expression,

Viewing all the timeouts/intervals in javascript?

泄露秘密 提交于 2019-11-26 06:00:48
问题 I\'m writing an application that utilizes JavaScript timeouts and intervals to update the page. Is there a way to see how many intervals are setup? I want to make sure that I\'m not accidentally going to kill the browser by having hundreds of intervals setup. Is this even an issue? 回答1: I don't think there is a way to enumerate active timers, but you could override window.setTimeout and window.clearTimeout and replace them with your own implementations which do some tracking and then call the

setInterval/setTimeout return value

瘦欲@ 提交于 2019-11-26 05:31:31
问题 Two questions: How is the value returned from setInterval and setTimeout (the ones used to clear the timers) calculated? Is it possible for both the functions to return the same value during runtime? For example: var a = setInterval(fn1, 1000); var b = setTimeout(fn2, 1000); Is it possible for a and b to have the same value? The first one is more of a for-my-knowledge question, but the second one is more important. 回答1: Returns a value which can be used to cancel the timer. So, it would seem

JavaScript setTimeout() won't wait to Execute?

♀尐吖头ヾ 提交于 2019-11-26 03:27:07
问题 Consider the following example: <script type=\"text/javascript\"> function alertBox(){ alert(\'Hello World!\'); } function doSomething(){ setInterval(alertBox(), 5000); //This is for generic purposes only }; function myFunction(){ setTimeout(doSomething(),3000); }; myFunction(); </script> What is it that causes this to execute IMMEDIATELY , rather than waiting the 3 seconds set, as well as only executing the alert ONCE , rather than at the scheduled 5 second intervals? Thanks for any help you

Postponing functions in python

社会主义新天地 提交于 2019-11-26 03:26:57
问题 In JavaScript I am used to being able to call functions to be executed at a later time, like this function foo() { alert(\'bar\'); } setTimeout(foo, 1000); This does not block the execution of other code. I do not know how to achieve something similar in Python. I can use sleep import time def foo(): print(\'bar\') time.sleep(1) foo() but this will block the execution of other code. (Actually in my case blocking Python would not be a problem in itself, but I would not be able to unit test the

How to create an accurate timer in javascript?

a 夏天 提交于 2019-11-26 03:14:35
问题 I need to create a simple but accurate timer. This is my code: var seconds = 0; setInterval(function() { timer.innerHTML = seconds++; }, 1000); After exactly 3600 seconds, it prints about 3500 seconds. Why is it not accurate ? How can I create an accurate timer ? 回答1: Why is it not accurate? Because you are using setTimeout() or setInterval() . They cannot be trusted, there are no accuracy guarantees for them. They are allowed to lag arbitrarily, and they do not keep a constant pace but tend

Will setInterval drift?

邮差的信 提交于 2019-11-26 02:38:22
问题 This is a pretty simple question really. If I use setInterval(something, 1000) , can I be completely sure that after, say, 31 days it will have triggered \"something\" exactly 60*60*24*31 times? Or is there any risk for so called drifting? 回答1: Here's a benchmark you can run in Firefox: var start = +new Date(); var count = 0; setInterval(function () { console.log((new Date() - start) % 1000, ++count, Math.round((new Date() - start)/1000)) }, 1000); First value should be as close to 0 or 1000

Calculating Page Load Time In JavaScript

こ雲淡風輕ζ 提交于 2019-11-26 02:27:46
问题 I am trying to make a webpage that, when it starts loading, uses an Interval to start a timer. When the page fully loads, it stops the timer, but 99% of the time i get time measurements of 0.00 or 0.01 even if it takes longer. Occasionally, it says something that makes more sense like .28 or 3.10 at some times. Here is the code if it helps: var hundredthstimer = 0; var secondplace = 0; function addinc(){ hundredthstimer += 1; if (inctimer == 100){ hundredthstimer = 0; secondplace += 1; } }

Jquery/Ajax call with timer

自作多情 提交于 2019-11-26 01:58:23
问题 I have a php page that echos out rows from a database. I want to call it via jquery/ajax every 30 seconds. But I also want to be able to call the page at any time so that if I add a record via the form, once the form submits I want the page via called to ajax to update the results right away. Can anyone point me in the right direction or provide some base code so I can try to figure this out? Still very new to jquery/ajax. 回答1: If you want to set something on a timer, you can use JavaScript's

Pass parameters in setInterval function

六眼飞鱼酱① 提交于 2019-11-26 01:48:39
问题 Please advise how to pass parameters into a function called using setInterval . My example setInterval(funca(10,3), 500); is incorrect. 回答1: You need to create an anonymous function so the actual function isn't executed right away. setInterval( function() { funca(10,3); }, 500 ); 回答2: now with ES5, bind method Function prototype : setInterval(funca.bind(null,10,3),500); Reference here 回答3: Add them as parameters to setInterval: setInterval(funca, 500, 10, 3); The syntax in your question uses