How to ping in JavaScript or jQuery?

后端 未结 2 2228
终归单人心
终归单人心 2021-02-14 02:43

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

2条回答
  •  無奈伤痛
    2021-02-14 02:58

    the lower response time is because by default the cache property is set to true, set it to false so that every time it goes to the server not the cache

    var ping = new Date;
    
    $.ajax({ type: "POST",
        url: "server.php",
        data: {....},
        cache:false,
        success: function(output){ 
    
            ping = new Date - ping;
    
        }
    });
    

提交回复
热议问题