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;








2















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";

?>









share|improve this question






























    2















    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";

    ?>









    share|improve this question


























      2












      2








      2


      1






      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";

      ?>









      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 3:39









      Cœur

      20.5k10119162




      20.5k10119162










      asked Apr 5 '11 at 18:54









      MikeMike

      2,878154464




      2,878154464






















          6 Answers
          6






          active

          oldest

          votes


















          6














          There are only two ways to do this:




          1. 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);



          2. For loop (this is a hack, so this is not preferred):



            for(i = 0; i < 500; i++);







          share|improve this answer

























          • 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


















          4














          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.






          share|improve this answer























          • I like the look of this…

            – Robin Layfield
            Mar 8 '13 at 15:00


















          3














          you can try the .delay() function...



          http://api.jquery.com/delay/






          share|improve this answer






























            1














            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().






            share|improve this answer























            • 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


















            1














            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, '');





            share|improve this answer

























            • 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


















            0














            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);





            share|improve this answer























              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
              );



              );













              draft saved

              draft discarded


















              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









              6














              There are only two ways to do this:




              1. 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);



              2. For loop (this is a hack, so this is not preferred):



                for(i = 0; i < 500; i++);







              share|improve this answer

























              • 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















              6














              There are only two ways to do this:




              1. 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);



              2. For loop (this is a hack, so this is not preferred):



                for(i = 0; i < 500; i++);







              share|improve this answer

























              • 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













              6












              6








              6







              There are only two ways to do this:




              1. 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);



              2. For loop (this is a hack, so this is not preferred):



                for(i = 0; i < 500; i++);







              share|improve this answer















              There are only two ways to do this:




              1. 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);



              2. For loop (this is a hack, so this is not preferred):



                for(i = 0; i < 500; i++);








              share|improve this answer














              share|improve this answer



              share|improve this answer








              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

















              • 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













              4














              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.






              share|improve this answer























              • I like the look of this…

                – Robin Layfield
                Mar 8 '13 at 15:00















              4














              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.






              share|improve this answer























              • I like the look of this…

                – Robin Layfield
                Mar 8 '13 at 15:00













              4












              4








              4







              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.






              share|improve this answer













              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.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              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

















              • 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











              3














              you can try the .delay() function...



              http://api.jquery.com/delay/






              share|improve this answer



























                3














                you can try the .delay() function...



                http://api.jquery.com/delay/






                share|improve this answer

























                  3












                  3








                  3







                  you can try the .delay() function...



                  http://api.jquery.com/delay/






                  share|improve this answer













                  you can try the .delay() function...



                  http://api.jquery.com/delay/







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 5 '11 at 18:59









                  stephen776stephen776

                  5,5411159112




                  5,5411159112





















                      1














                      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().






                      share|improve this answer























                      • 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















                      1














                      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().






                      share|improve this answer























                      • 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













                      1












                      1








                      1







                      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().






                      share|improve this answer













                      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().







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      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

















                      • 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











                      1














                      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, '');





                      share|improve this answer

























                      • 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















                      1














                      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, '');





                      share|improve this answer

























                      • 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













                      1












                      1








                      1







                      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, '');





                      share|improve this answer















                      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, '');






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      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

















                      • 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











                      0














                      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);





                      share|improve this answer



























                        0














                        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);





                        share|improve this answer

























                          0












                          0








                          0







                          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);





                          share|improve this answer













                          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);






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 5 '11 at 19:03









                          John StricklerJohn Strickler

                          21.2k44665




                          21.2k44665



























                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해