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 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题