我想创建一个简单的脚本来帮助我计算上传图像到服务器所需的时间
$(document).ready(function(){
$("#but_upload").click(function(){
var fd = new FormData();
var files = $('#file')[0].files[0];
fd.append('file',files);
$.ajax({
url: 'http://uploadtomyapi.com',
type: 'post',
data: fd,
contentType: false,
processData: false,
success: function(response){
// done my calculation here
});
});
});
我不知道这是更好的方法,但我是新手,有人能帮我吗?非常感谢。
类似的东西,然后计算开始值和结束值之间的差(就像Taplar在上面的评论中提到的那样(。
<script>
var startTime, EndTime;
$(document).ready(function () {
$("#but_upload").click(function () {
var fd = new FormData();
var files = $('#file')[0].files[0];
fd.append('file', files);
$.ajax({
url: 'http://uploadtomyapi.com',
type: 'post',
data: fd,
contentType: false,
processData: false,
beforeSend: function () {
startTime = Date.now();
},
success: function (response) {
// done my calculation here
},
complete: function () {
endTime = Date.now();
}
});
});
});
</script>