How to pause jQuery code for few milliseconds?fire javascript function after partial view is rendered in C# MVCJquery Toggle not workingIs there an “exists” function for jQuery?How do JavaScript closures work?How do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How do I redirect to another webpage?How to check whether a checkbox is checked in jQuery?How to check whether a string contains a substring in JavaScript?How to decide when to use Node.js?How do I remove a particular element from an array in JavaScript?“Thinking in AngularJS” if I have a jQuery background?
Print the phrase "And she said, 'But that's his.'" using only the alphabet
I have found ports on my Samsung smart tv running a display service. What can I do with it?
Digital signature that is only verifiable by one specific person
At what temperature should the earth be cooked to prevent human infection?
How to get imageUrl using Jquery in magento2?
How do I gain the trust of other PCs?
First occurrence in the Sixers sequence
Leaving job close to major deadlines
Is it a bad idea to have a pen name with only an initial for a surname?
Testing thermite for chemical properties
How do credit card companies know what type of business I'm paying for?
What kind of chart is this?
What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?
TiKZ won't graph 1/sqrt(x)
Having some issue with notation in a Hilbert space
...and then she held the gun
Using roof rails to set up hammock
Should I email my professor to clear up a (possibly very irrelevant) awkward misunderstanding?
Think Outside the Box - A Riley Riddle
Is the Infant Mortality rate among African-Americans babies in Youngstown, Ohio greater than that of babies in Iran?
How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?
New Site Design!
Is it possible for underground bunkers on different continents to be connected?
What is the color associated with lukewarm?
How to pause jQuery code for few milliseconds?
fire javascript function after partial view is rendered in C# MVCJquery Toggle not workingIs there an “exists” function for jQuery?How do JavaScript closures work?How do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How do I redirect to another webpage?How to check whether a checkbox is checked in jQuery?How to check whether a string contains a substring in JavaScript?How to decide when to use Node.js?How do I remove a particular element from an array in JavaScript?“Thinking in AngularJS” if I have a jQuery background?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm using jQuery Ajax functions to auto update my database through cron. Since there are a lot of rows to be updated, I'd like to pause the code for few milliseconds each iretation. What would be the best way to do it?
Here's sample of my code:
<?php
$zdroje = $db->select('zdroje', 'id!=1');
echo "<script type='text/javascript'>n
$(document).ready(function() n";
foreach($zdroje as $zdroj)
echo "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// pause here!
);n";
// end: foreach
echo ");n</script>n";
?>
javascript jquery delay
add a comment |
I'm using jQuery Ajax functions to auto update my database through cron. Since there are a lot of rows to be updated, I'd like to pause the code for few milliseconds each iretation. What would be the best way to do it?
Here's sample of my code:
<?php
$zdroje = $db->select('zdroje', 'id!=1');
echo "<script type='text/javascript'>n
$(document).ready(function() n";
foreach($zdroje as $zdroj)
echo "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// pause here!
);n";
// end: foreach
echo ");n</script>n";
?>
javascript jquery delay
add a comment |
I'm using jQuery Ajax functions to auto update my database through cron. Since there are a lot of rows to be updated, I'd like to pause the code for few milliseconds each iretation. What would be the best way to do it?
Here's sample of my code:
<?php
$zdroje = $db->select('zdroje', 'id!=1');
echo "<script type='text/javascript'>n
$(document).ready(function() n";
foreach($zdroje as $zdroj)
echo "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// pause here!
);n";
// end: foreach
echo ");n</script>n";
?>
javascript jquery delay
I'm using jQuery Ajax functions to auto update my database through cron. Since there are a lot of rows to be updated, I'd like to pause the code for few milliseconds each iretation. What would be the best way to do it?
Here's sample of my code:
<?php
$zdroje = $db->select('zdroje', 'id!=1');
echo "<script type='text/javascript'>n
$(document).ready(function() n";
foreach($zdroje as $zdroj)
echo "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// pause here!
);n";
// end: foreach
echo ");n</script>n";
?>
javascript jquery delay
javascript jquery delay
edited Mar 25 at 3:39
Cœur
20.5k10119162
20.5k10119162
asked Apr 5 '11 at 18:54
MikeMike
2,878154464
2,878154464
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
There are only two ways to do this:
Use setTimeout (for example, 10 milliseconds):
setTimeout(function ()
$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// do stuff here!
);
, 10);For loop (this is a hack, so this is not preferred):
for(i = 0; i < 500; i++);
I like the idea, so to implement this I just write ($i * 10) insted of 10, right?
– Mike
Apr 5 '11 at 19:03
10 is the number of milliseconds to wait before executing the code. Change it to whatever makes sense to your application.
– beatgammit
Apr 5 '11 at 19:05
add a comment |
I suggest you take a look at jQuery's new defer system. Here's a good tutorial:
http://www.erichynds.com/jquery/using-deferreds-in-jquery/
Essentially, you can create a "hold" promise like this:
function hold(delay)
var dfd = $.Deferred();
setTimeout(function()
dfd.resolve();
, delay);
return dfd.promise();
Then string together ajax requests with it like this:
$.when($.post('yourLongUrlHere'))
.then(hold(500))
.then($.post('anotherUrl'))
.then(hold(500))
.then($.post('somethingElse.php'));
This will make each ajax request in order waiting 500 miliseconds in between each.
Should handle what you asked about w/o a problem.
I like the look of this…
– Robin Layfield
Mar 8 '13 at 15:00
add a comment |
you can try the .delay() function...
http://api.jquery.com/delay/
add a comment |
A clumsy approach might arguably be to use JavaScript's setTimeout() method, but I'd recommend you look into the jQuery functions, $.ajaxComplete(), $.ajaxStart() and $.ajaxStop().
Well, there really isn't somethig like pause(1); function? =/
– Mike
Apr 5 '11 at 18:59
Browser's JS don't have the syncronous blocking pause functionsality. It is just the way things work :)
– zindel
Apr 5 '11 at 19:03
add a comment |
I suppose you'd want to generate the chained call instead of plain list. I.e. what you get now is:
$.post(...)
$.post(...)
...
$.post(...)
You'd want to get something like this:
$.post(url1, function(data)
setTimeout(function()
$.post(url2, function(data)
setTimeout(function() $.post(url3), 500);
);
, 500);
);
Having that you're using PHP to generate the JavaScript code - it shouldn't be too difficult to produce the code like this. Hope this helps.
Edit: Try generating it like this
$code = "%s";
foreach($sources as $source)
$part = "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '$source['id']' , function(data)
setTimeout(function()
%s
, 500);
);"
$code = sprintf($code, $part);
$code = sprintf($code, '');
Well, this could also work, but what do you think about tjameson's answer and what would work better?
– Mike
Apr 5 '11 at 19:07
well, #2 his answer is hack (as stated:)) and don't guarantee anything. The #1 point is a good start to the solution I offered. Look, if you do several setTimeout(post, 500) one by one - you'll end up with first call paused but no pause is guaranteed between calls at all, while the solution from my post definitely makes pauses between postings
– zindel
Apr 5 '11 at 19:13
Good addition of the foreach for generating the nested setTimeouts. This may be better than mine, because it would guarantee that there is a 500 millisecond break between post calls.
– beatgammit
Apr 6 '11 at 9:28
add a comment |
You can't pause the JavaScript engine from processing code. JS has code that runs asynchronously - for example, a response from an AJAX request comes back and the callback function is executed.
setTimeout is your best friend in regards to delaying the execution of a particular function.
//Executes an alert exactly 1 second later
setTimeout(function()
alert('hello world');
, 1000);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5556971%2fhow-to-pause-jquery-code-for-few-milliseconds%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are only two ways to do this:
Use setTimeout (for example, 10 milliseconds):
setTimeout(function ()
$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// do stuff here!
);
, 10);For loop (this is a hack, so this is not preferred):
for(i = 0; i < 500; i++);
I like the idea, so to implement this I just write ($i * 10) insted of 10, right?
– Mike
Apr 5 '11 at 19:03
10 is the number of milliseconds to wait before executing the code. Change it to whatever makes sense to your application.
– beatgammit
Apr 5 '11 at 19:05
add a comment |
There are only two ways to do this:
Use setTimeout (for example, 10 milliseconds):
setTimeout(function ()
$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// do stuff here!
);
, 10);For loop (this is a hack, so this is not preferred):
for(i = 0; i < 500; i++);
I like the idea, so to implement this I just write ($i * 10) insted of 10, right?
– Mike
Apr 5 '11 at 19:03
10 is the number of milliseconds to wait before executing the code. Change it to whatever makes sense to your application.
– beatgammit
Apr 5 '11 at 19:05
add a comment |
There are only two ways to do this:
Use setTimeout (for example, 10 milliseconds):
setTimeout(function ()
$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// do stuff here!
);
, 10);For loop (this is a hack, so this is not preferred):
for(i = 0; i < 500; i++);
There are only two ways to do this:
Use setTimeout (for example, 10 milliseconds):
setTimeout(function ()
$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '".$zdroj['id']."' , function(data)
// do stuff here!
);
, 10);For loop (this is a hack, so this is not preferred):
for(i = 0; i < 500; i++);
edited Apr 6 '11 at 9:25
answered Apr 5 '11 at 19:00
beatgammitbeatgammit
13.4k1675117
13.4k1675117
I like the idea, so to implement this I just write ($i * 10) insted of 10, right?
– Mike
Apr 5 '11 at 19:03
10 is the number of milliseconds to wait before executing the code. Change it to whatever makes sense to your application.
– beatgammit
Apr 5 '11 at 19:05
add a comment |
I like the idea, so to implement this I just write ($i * 10) insted of 10, right?
– Mike
Apr 5 '11 at 19:03
10 is the number of milliseconds to wait before executing the code. Change it to whatever makes sense to your application.
– beatgammit
Apr 5 '11 at 19:05
I like the idea, so to implement this I just write ($i * 10) insted of 10, right?
– Mike
Apr 5 '11 at 19:03
I like the idea, so to implement this I just write ($i * 10) insted of 10, right?
– Mike
Apr 5 '11 at 19:03
10 is the number of milliseconds to wait before executing the code. Change it to whatever makes sense to your application.
– beatgammit
Apr 5 '11 at 19:05
10 is the number of milliseconds to wait before executing the code. Change it to whatever makes sense to your application.
– beatgammit
Apr 5 '11 at 19:05
add a comment |
I suggest you take a look at jQuery's new defer system. Here's a good tutorial:
http://www.erichynds.com/jquery/using-deferreds-in-jquery/
Essentially, you can create a "hold" promise like this:
function hold(delay)
var dfd = $.Deferred();
setTimeout(function()
dfd.resolve();
, delay);
return dfd.promise();
Then string together ajax requests with it like this:
$.when($.post('yourLongUrlHere'))
.then(hold(500))
.then($.post('anotherUrl'))
.then(hold(500))
.then($.post('somethingElse.php'));
This will make each ajax request in order waiting 500 miliseconds in between each.
Should handle what you asked about w/o a problem.
I like the look of this…
– Robin Layfield
Mar 8 '13 at 15:00
add a comment |
I suggest you take a look at jQuery's new defer system. Here's a good tutorial:
http://www.erichynds.com/jquery/using-deferreds-in-jquery/
Essentially, you can create a "hold" promise like this:
function hold(delay)
var dfd = $.Deferred();
setTimeout(function()
dfd.resolve();
, delay);
return dfd.promise();
Then string together ajax requests with it like this:
$.when($.post('yourLongUrlHere'))
.then(hold(500))
.then($.post('anotherUrl'))
.then(hold(500))
.then($.post('somethingElse.php'));
This will make each ajax request in order waiting 500 miliseconds in between each.
Should handle what you asked about w/o a problem.
I like the look of this…
– Robin Layfield
Mar 8 '13 at 15:00
add a comment |
I suggest you take a look at jQuery's new defer system. Here's a good tutorial:
http://www.erichynds.com/jquery/using-deferreds-in-jquery/
Essentially, you can create a "hold" promise like this:
function hold(delay)
var dfd = $.Deferred();
setTimeout(function()
dfd.resolve();
, delay);
return dfd.promise();
Then string together ajax requests with it like this:
$.when($.post('yourLongUrlHere'))
.then(hold(500))
.then($.post('anotherUrl'))
.then(hold(500))
.then($.post('somethingElse.php'));
This will make each ajax request in order waiting 500 miliseconds in between each.
Should handle what you asked about w/o a problem.
I suggest you take a look at jQuery's new defer system. Here's a good tutorial:
http://www.erichynds.com/jquery/using-deferreds-in-jquery/
Essentially, you can create a "hold" promise like this:
function hold(delay)
var dfd = $.Deferred();
setTimeout(function()
dfd.resolve();
, delay);
return dfd.promise();
Then string together ajax requests with it like this:
$.when($.post('yourLongUrlHere'))
.then(hold(500))
.then($.post('anotherUrl'))
.then(hold(500))
.then($.post('somethingElse.php'));
This will make each ajax request in order waiting 500 miliseconds in between each.
Should handle what you asked about w/o a problem.
answered Apr 5 '11 at 19:04
ShakakaiShakakai
3,05911218
3,05911218
I like the look of this…
– Robin Layfield
Mar 8 '13 at 15:00
add a comment |
I like the look of this…
– Robin Layfield
Mar 8 '13 at 15:00
I like the look of this…
– Robin Layfield
Mar 8 '13 at 15:00
I like the look of this…
– Robin Layfield
Mar 8 '13 at 15:00
add a comment |
you can try the .delay() function...
http://api.jquery.com/delay/
add a comment |
you can try the .delay() function...
http://api.jquery.com/delay/
add a comment |
you can try the .delay() function...
http://api.jquery.com/delay/
you can try the .delay() function...
http://api.jquery.com/delay/
answered Apr 5 '11 at 18:59
stephen776stephen776
5,5411159112
5,5411159112
add a comment |
add a comment |
A clumsy approach might arguably be to use JavaScript's setTimeout() method, but I'd recommend you look into the jQuery functions, $.ajaxComplete(), $.ajaxStart() and $.ajaxStop().
Well, there really isn't somethig like pause(1); function? =/
– Mike
Apr 5 '11 at 18:59
Browser's JS don't have the syncronous blocking pause functionsality. It is just the way things work :)
– zindel
Apr 5 '11 at 19:03
add a comment |
A clumsy approach might arguably be to use JavaScript's setTimeout() method, but I'd recommend you look into the jQuery functions, $.ajaxComplete(), $.ajaxStart() and $.ajaxStop().
Well, there really isn't somethig like pause(1); function? =/
– Mike
Apr 5 '11 at 18:59
Browser's JS don't have the syncronous blocking pause functionsality. It is just the way things work :)
– zindel
Apr 5 '11 at 19:03
add a comment |
A clumsy approach might arguably be to use JavaScript's setTimeout() method, but I'd recommend you look into the jQuery functions, $.ajaxComplete(), $.ajaxStart() and $.ajaxStop().
A clumsy approach might arguably be to use JavaScript's setTimeout() method, but I'd recommend you look into the jQuery functions, $.ajaxComplete(), $.ajaxStart() and $.ajaxStop().
answered Apr 5 '11 at 18:57
Phil.WheelerPhil.Wheeler
13.2k985147
13.2k985147
Well, there really isn't somethig like pause(1); function? =/
– Mike
Apr 5 '11 at 18:59
Browser's JS don't have the syncronous blocking pause functionsality. It is just the way things work :)
– zindel
Apr 5 '11 at 19:03
add a comment |
Well, there really isn't somethig like pause(1); function? =/
– Mike
Apr 5 '11 at 18:59
Browser's JS don't have the syncronous blocking pause functionsality. It is just the way things work :)
– zindel
Apr 5 '11 at 19:03
Well, there really isn't somethig like pause(1); function? =/
– Mike
Apr 5 '11 at 18:59
Well, there really isn't somethig like pause(1); function? =/
– Mike
Apr 5 '11 at 18:59
Browser's JS don't have the syncronous blocking pause functionsality. It is just the way things work :)
– zindel
Apr 5 '11 at 19:03
Browser's JS don't have the syncronous blocking pause functionsality. It is just the way things work :)
– zindel
Apr 5 '11 at 19:03
add a comment |
I suppose you'd want to generate the chained call instead of plain list. I.e. what you get now is:
$.post(...)
$.post(...)
...
$.post(...)
You'd want to get something like this:
$.post(url1, function(data)
setTimeout(function()
$.post(url2, function(data)
setTimeout(function() $.post(url3), 500);
);
, 500);
);
Having that you're using PHP to generate the JavaScript code - it shouldn't be too difficult to produce the code like this. Hope this helps.
Edit: Try generating it like this
$code = "%s";
foreach($sources as $source)
$part = "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '$source['id']' , function(data)
setTimeout(function()
%s
, 500);
);"
$code = sprintf($code, $part);
$code = sprintf($code, '');
Well, this could also work, but what do you think about tjameson's answer and what would work better?
– Mike
Apr 5 '11 at 19:07
well, #2 his answer is hack (as stated:)) and don't guarantee anything. The #1 point is a good start to the solution I offered. Look, if you do several setTimeout(post, 500) one by one - you'll end up with first call paused but no pause is guaranteed between calls at all, while the solution from my post definitely makes pauses between postings
– zindel
Apr 5 '11 at 19:13
Good addition of the foreach for generating the nested setTimeouts. This may be better than mine, because it would guarantee that there is a 500 millisecond break between post calls.
– beatgammit
Apr 6 '11 at 9:28
add a comment |
I suppose you'd want to generate the chained call instead of plain list. I.e. what you get now is:
$.post(...)
$.post(...)
...
$.post(...)
You'd want to get something like this:
$.post(url1, function(data)
setTimeout(function()
$.post(url2, function(data)
setTimeout(function() $.post(url3), 500);
);
, 500);
);
Having that you're using PHP to generate the JavaScript code - it shouldn't be too difficult to produce the code like this. Hope this helps.
Edit: Try generating it like this
$code = "%s";
foreach($sources as $source)
$part = "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '$source['id']' , function(data)
setTimeout(function()
%s
, 500);
);"
$code = sprintf($code, $part);
$code = sprintf($code, '');
Well, this could also work, but what do you think about tjameson's answer and what would work better?
– Mike
Apr 5 '11 at 19:07
well, #2 his answer is hack (as stated:)) and don't guarantee anything. The #1 point is a good start to the solution I offered. Look, if you do several setTimeout(post, 500) one by one - you'll end up with first call paused but no pause is guaranteed between calls at all, while the solution from my post definitely makes pauses between postings
– zindel
Apr 5 '11 at 19:13
Good addition of the foreach for generating the nested setTimeouts. This may be better than mine, because it would guarantee that there is a 500 millisecond break between post calls.
– beatgammit
Apr 6 '11 at 9:28
add a comment |
I suppose you'd want to generate the chained call instead of plain list. I.e. what you get now is:
$.post(...)
$.post(...)
...
$.post(...)
You'd want to get something like this:
$.post(url1, function(data)
setTimeout(function()
$.post(url2, function(data)
setTimeout(function() $.post(url3), 500);
);
, 500);
);
Having that you're using PHP to generate the JavaScript code - it shouldn't be too difficult to produce the code like this. Hope this helps.
Edit: Try generating it like this
$code = "%s";
foreach($sources as $source)
$part = "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '$source['id']' , function(data)
setTimeout(function()
%s
, 500);
);"
$code = sprintf($code, $part);
$code = sprintf($code, '');
I suppose you'd want to generate the chained call instead of plain list. I.e. what you get now is:
$.post(...)
$.post(...)
...
$.post(...)
You'd want to get something like this:
$.post(url1, function(data)
setTimeout(function()
$.post(url2, function(data)
setTimeout(function() $.post(url3), 500);
);
, 500);
);
Having that you're using PHP to generate the JavaScript code - it shouldn't be too difficult to produce the code like this. Hope this helps.
Edit: Try generating it like this
$code = "%s";
foreach($sources as $source)
$part = "$.post( '/adminator/menu/2zajezdy/tools/01otnXml/requests.php', 'updateXML': '$source['id']' , function(data)
setTimeout(function()
%s
, 500);
);"
$code = sprintf($code, $part);
$code = sprintf($code, '');
edited Apr 5 '11 at 19:25
answered Apr 5 '11 at 19:02
zindelzindel
1,651911
1,651911
Well, this could also work, but what do you think about tjameson's answer and what would work better?
– Mike
Apr 5 '11 at 19:07
well, #2 his answer is hack (as stated:)) and don't guarantee anything. The #1 point is a good start to the solution I offered. Look, if you do several setTimeout(post, 500) one by one - you'll end up with first call paused but no pause is guaranteed between calls at all, while the solution from my post definitely makes pauses between postings
– zindel
Apr 5 '11 at 19:13
Good addition of the foreach for generating the nested setTimeouts. This may be better than mine, because it would guarantee that there is a 500 millisecond break between post calls.
– beatgammit
Apr 6 '11 at 9:28
add a comment |
Well, this could also work, but what do you think about tjameson's answer and what would work better?
– Mike
Apr 5 '11 at 19:07
well, #2 his answer is hack (as stated:)) and don't guarantee anything. The #1 point is a good start to the solution I offered. Look, if you do several setTimeout(post, 500) one by one - you'll end up with first call paused but no pause is guaranteed between calls at all, while the solution from my post definitely makes pauses between postings
– zindel
Apr 5 '11 at 19:13
Good addition of the foreach for generating the nested setTimeouts. This may be better than mine, because it would guarantee that there is a 500 millisecond break between post calls.
– beatgammit
Apr 6 '11 at 9:28
Well, this could also work, but what do you think about tjameson's answer and what would work better?
– Mike
Apr 5 '11 at 19:07
Well, this could also work, but what do you think about tjameson's answer and what would work better?
– Mike
Apr 5 '11 at 19:07
well, #2 his answer is hack (as stated:)) and don't guarantee anything. The #1 point is a good start to the solution I offered. Look, if you do several setTimeout(post, 500) one by one - you'll end up with first call paused but no pause is guaranteed between calls at all, while the solution from my post definitely makes pauses between postings
– zindel
Apr 5 '11 at 19:13
well, #2 his answer is hack (as stated:)) and don't guarantee anything. The #1 point is a good start to the solution I offered. Look, if you do several setTimeout(post, 500) one by one - you'll end up with first call paused but no pause is guaranteed between calls at all, while the solution from my post definitely makes pauses between postings
– zindel
Apr 5 '11 at 19:13
Good addition of the foreach for generating the nested setTimeouts. This may be better than mine, because it would guarantee that there is a 500 millisecond break between post calls.
– beatgammit
Apr 6 '11 at 9:28
Good addition of the foreach for generating the nested setTimeouts. This may be better than mine, because it would guarantee that there is a 500 millisecond break between post calls.
– beatgammit
Apr 6 '11 at 9:28
add a comment |
You can't pause the JavaScript engine from processing code. JS has code that runs asynchronously - for example, a response from an AJAX request comes back and the callback function is executed.
setTimeout is your best friend in regards to delaying the execution of a particular function.
//Executes an alert exactly 1 second later
setTimeout(function()
alert('hello world');
, 1000);
add a comment |
You can't pause the JavaScript engine from processing code. JS has code that runs asynchronously - for example, a response from an AJAX request comes back and the callback function is executed.
setTimeout is your best friend in regards to delaying the execution of a particular function.
//Executes an alert exactly 1 second later
setTimeout(function()
alert('hello world');
, 1000);
add a comment |
You can't pause the JavaScript engine from processing code. JS has code that runs asynchronously - for example, a response from an AJAX request comes back and the callback function is executed.
setTimeout is your best friend in regards to delaying the execution of a particular function.
//Executes an alert exactly 1 second later
setTimeout(function()
alert('hello world');
, 1000);
You can't pause the JavaScript engine from processing code. JS has code that runs asynchronously - for example, a response from an AJAX request comes back and the callback function is executed.
setTimeout is your best friend in regards to delaying the execution of a particular function.
//Executes an alert exactly 1 second later
setTimeout(function()
alert('hello world');
, 1000);
answered Apr 5 '11 at 19:03
John StricklerJohn Strickler
21.2k44665
21.2k44665
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5556971%2fhow-to-pause-jquery-code-for-few-milliseconds%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown