title: How to ping in JavaScript or jQuery?
body: <p>I want to create a game-like ping in Javascript, just like the game Counter Strike for example. I'm doing an AJAX call to the server (MySQL) and want to calculate the time that's taken, but I'm either calculating it wrong or have the wrong idea of pinging. Here is the code I have so far:</p>
  
  <pre><code>var time_stamp = new Date;
  
  $.ajax({ type: "POST",
      url: "server.php",
      data: {....},
      success: function(output){ 
  
          ping = new Date - time_stamp;
  
      }
  }); // btw, this code works fine now for ping
  </code></pre>
  
  <p>The problem is that sometimes I get 0ms or 3ms. Is this okay? It seems very fast to go to <code>server.php</code>, connect to database, select some rows, and return some data. Yes, this is on localhost, so it should be fast, but is it meant to be this fast? Should I be calculating it at FPS, or just each call to <code>server.php</code>?</p>