csdn产品小助手 2017-02-18 13:13 采纳率: 0%
浏览 28

JavaScript中的XMLHttpRequest

I have done Laravel/PHP web server and run it on http://120.77.44.4/ Now I need to calculate Network Speed in JavaScript. To implement this, I tried to send a HTTP request to the server and calculate the response data size and time. When I divide the response data size by time, I can get the download speed of the client. I tried it myself, but I can not get as I need.

This is the JavaScript function in php code.

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://120.77.44.4/RequestSpeed", true);

xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
    if (xmlhttp.status == 200) {
      alert('OK, 200');
    } else if (xmlhttp.status == 400) {
      alert('There was an error 400');
    } else {
      alert('something else other than 200 was returned');
    }
  }
};

xmlhttp.send();

This is the code in server.

public function RequestSpeed() {
  file_get_contents('./test.txt', true);
  return response();
}

The server was done by using Laravel/MySql.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算