title: How to run a query when the page is finished loading?
body: <p>I have a table like this:</p>
  
  <pre><code>// last_seen
  +----+---------+--------------+
  | id | id_user |     time     |
  +----+---------+--------------+
  | 1  | 545     | 1339412843   |
  | 2  | 653     | 1339422601   |
  | 3  | 813     | 1339412612   |
  | 4  | 1030    | 1339717631   |
  +----+---------+--------------+
  </code></pre>
  
  <p>Every user has a row in table above. That row contains a <em>unix_time</em> which declares the time of last seen for each user.</p>
  
  <p>Also I have this PHP script <em>(named <code>update_last_seen.php</code>)</em> which updates last seen for each user per every request:</p>
  
  <pre><code>// user is logged
  if( isset($_SESSION["LoginValidation"]) &amp;&amp; $_SESSION["LoginValidation"] == 1 ) {
  
     // it is ajax request
     if( !empty($_SERVER["HTTP_X_REQUESTED_WITH"]) &amp;&amp;
         strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) === "xmlhttprequest" ) {
  
          $db
          -&gt;prepare("UPDATE last_seen SET time = ? WHERE id_user = ?")
          -&gt;execute(array(time(), $_SESSION['id']));
  
     } -- ajax
  } -- logged
  </code></pre>
  
  <p>Currently I run script above first of all into <code>index.php</code>. I mean each page updates <code>last_seen</code> table before loading. So the request does get slowed down by the update.</p>
  
  <p>Now I'd make that an AJAX push request when the page finished loading. Is there any JS event to detect page is loaded completely?</p>