[英]How to alert time process using jQuery in the proper way?
I want to show the time of process of my php code using jQuery 我想使用jQuery显示我的PHP代码的处理时间
My php code example : 我的PHP代码示例:
<?php
//some queries to database
?>
Here's my jQuery: 这是我的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");
}
});
The alert show this : 警报显示如下:
Can somebody help me how to make it more readable ? 有人可以帮助我如何使其更具可读性吗? Because I dont know what value that showed on my alert.
因为我不知道警报中显示了什么值。 Thank you.
谢谢。
I've modified my ajax request to be like this : 我已经将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");
}
});
But the alert didn't show the time
value. 但是警报未显示
time
值。
Did I do something wrong ? 我做错什么了吗 ? Please tell me.
请告诉我。
This is the latest alert : 这是最新的警报:
How to make it more simple ? 如何使其更简单?
You could always return in the action.php
response a key called time
containing the total time the request took, then you can handle this in your success section and display as you wish. 您始终可以在
action.php
响应中返回一个名为time
的键,其中包含请求所花费的总时间,然后可以在成功部分中进行处理,并根据需要显示。
You could generate the value of time
with: 您可以使用以下方法生成
time
值:
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.