Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that in some cases the first PHP script has not finished running before you click the button that loads the second PHP script (like I implied before in my comment). The fact that this happens is related to how scripts are scheduled by the webserver (which is a different subject entirely).</p> <p>You thus need to make sure that when you click the button that runs the second script, the first script has completely finished running. </p> <p>Because in my knowledge, javascript does not allow blocking/signaling on a variable (like Java does), you'll have to use a more 'dirty' technique called busy waiting.</p> <p>The best way to do this, is to include an extra variable in the javascript you are using.</p> <pre><code>var wait = false; function reloadSecond (){ if (wait){ setTimeout('reloadSecond()',200); } else { $("#div").load('second.php'); } } $(".userdata").click(function() { wait = true; $.post("first.php", $("form#checkboxes").serialize(), function(){ wait = false; }); }); $(function() { $("#button").click(reloadSecond); }) </code></pre> <p>While 'busy waiting' is generally not considered the most elegant solution, I think you don't have many other options in this case (except for serverside push, which is much more complicated). Additionally, you'll probably only incur the extra 200 millisecond (or less, you can of course change this value) waiting time once or twice.</p> <p>(side note: I assume that javascript is single threaded here, which is true in almost all cases: <a href="https://stackoverflow.com/questions/2734025/is-javascript-guaranteed-to-be-single-threaded">Is JavaScript guaranteed to be single-threaded?</a>).</p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload