When someone clicks a button on my web page, this JavaScript code runs:
function count() {
var xmlHttp = getXMLHttp(); // XMLHttpRequest object
xmlHttp.open("GET", "count.php", true);
xmlHttp.send(null);
}
Then, this PHP script gets executed: (a common)
<?php
mysql_connect("host","username","password");
mysql_select_db('database');
mysql_query('UPDATE table SET field = field + 1');
?>
The problem may vary. Lets say I click ten times, it only registers 8 or something. Sometimes it works, other times it does not.
There is always a solution…
Quick Fix Solution @
Make Your AJAX call synchronous. Note: This will make the Generate button seem stuck during the duration of execution and I think you don’t want that (as you are keeping all the names in JS array for faster loading… Yes i visited your link… thanks for posting it)
Better Solution
Change your PHP to get countForPHP from Request.QueryString and update SQL accordingly
Note: Counts will be lost when the website is closed and that 60 sec lot is not committed to server. To take care of that you may want to call submitCount on window.onbeforeunload