Okay, so I have a snippet of code from a website containing a button:
<button type="button"
onclick="laser(); $.post('sheepDB.php', { vic: vic, num: numVics });">
Activate Her Powers!
</button>
However, when I click the button the first time, the first function executes, but if I click it a second time, both the first function AND the Ajax call are executed. How do I get onclick to execute them sequentially? (laser() determines the values sent by the Ajax request, so it must be sequential).
Javascript does execute sequentially. However, AJAX is asynchronous (hence the A), which means that Javascript execution continues while the AJAX request is taking place. If you trigger your onclick a second time before the first AJAX request completes, it is possible that the first AJAX request will not complete before the second click (and thus look like it’s only happening once).