2017-04-05 23 views
0

我想使用jQuery如何以正確的方式提醒使用jQuery的時間過程?


我的PHP代碼示例來說明我的PHP代碼的過程的時間:

<?php 
    //some queries to database 
?> 

這裏是我的jQuery:

$.ajax({ 
     type: "POST", 
     url: "action.php", 
     data: { 
      action: "simpanFitur", fitur: $('#feature :selected').val() 
     }, 
     success: function(){ 
      var stop = new Date().getTime()-start; 
      alert("Tersimpan.\n Lama proses : " + stop); 
     }, 
     error: function(cek){ 
      alert("Error"); 
     } 
    }); 

警報顯示此:

enter image description here

有人能幫助我如何讓它更具可讀性嗎?因爲我不知道我的警報顯示了什麼價值。謝謝。

我修改我的Ajax請求是這樣的:

$.ajax({ 
     type: "POST", 
     url: "action.php", 
     data: { 
      action: "simpanFitur", fitur: $('#feature :selected').val() 
     }, 
     success: function(time){ 
      alert("Tersimpan.\nLama proses : " + time); 
     }, 
     error: function(){ 
      alert("Error"); 
     } 
    }); 

但警報並未出現time值。

enter image description here

難道我做錯了什麼?請告訴我。

這是最新的警報:

enter image description here

如何使它更簡單嗎?

+0

如何https://nodejs.org/api/console.html#console_console_time_label? –

+0

時差以毫秒爲單位。以1000分,以秒爲單位。在你的情況488.165秒 –

+0

你也可以在Chrome/Firefox開發者工具中找到有用的信息[看這裏](https://developers.google.com/web/tools/chrome-devtools/network-performance/resource-loading)爲什麼你需要以這種方式跟蹤時間嗎? –

回答

0

您總是可以在action.php響應中返回一個名爲time的密鑰,其中包含請求總共花費的時間,然後您可以在您的成功部分處理該信息並按需要顯示。

您可以生成的time與價值:

$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; 
+0

如何在幾秒鐘或幾分鐘內完成? – kurniawan26

+0

'$ seconds = $ time/1000000;' – Ryan

+0

嗨,我應該在哪裏放置'$ time = microtime(true) - $ _SERVER [「REQUEST_TIME_FLOAT」];'?在我的PHP的頂部? – kurniawan26

相關問題