I have a php / mysql / jquery web app that makes 13 ajax queries to various APIs and stores the result in a database table. To each result I assign a score and when all the results have completed I want to display a 'total score'.
My problem is knowing when all the ajax queries have completed and all the results are in and ready to be tallied.
Here's the existing workflow:
- User enters data in the query box and hits submit.
- Page reloads and inserts a 'scan id' into a 'scan_index' table.
- Page then executes a jquery $.get function for each of 13 queries ( all queries use the same javascript function to perform their work ).
- As each result is returned, the result is inserted into a 'scans' table using the previously inserted 'scan id' to allow association with the proper scan. The result is also displayed to the user along with that result's score.
At this point what I would do is retrieve all results in the scans table using the scan_id value, and total up the score and display that to the user.
But my problem is knowing when to kick off the query to retrieve all the totals. Any given query could take up to 10 seconds ( my predefined timeout value ) before completing ( or failing ), but they usually take only about 3 seconds max to complete.
So, without knowing when a query will complete, how can I tell when all queries have completed?