0

XMLHttpRequest Level 2 adds a number of more meaningful events over the onreadystatechange one.

Is there a correspondence between some of these events and the readyState values?

As far as I can tell:

1   loadstart
2   progress
3   ?
4   loadend; load

I haven’t worked out equivalent for 3, which is a bit vague anyway.

4

1 回答 1

0

这是我使用以下代码观察到的:

var oReq = new XMLHttpRequest();

oReq.addEventListener("progress", ev);
oReq.addEventListener("load", ev);
oReq.addEventListener("loadstart", ev);
oReq.addEventListener("loadend", ev);
oReq.addEventListener("readystatechange", ev);


oReq.open('GET', '/blah');

function ev(e) {
    console.log(e.type, oReq.readyState);
}
oReq.send();

输出结果

readystatechange 1
loadstart 1
readystatechange 2
readystatechange 3
progress 3
readystatechange 4
load 4
loadend 4

所以看起来是

  1. 加载启动
  2. ???- 没有等价物 - (这是收到的标头)
  3. 进步
  4. 加载/加载端
于 2016-09-17T01:58:21.320 回答