小编典典

XMLHttpRequest中的onload是否等于readyState == 4?

javascript

正如我所知道的,我对xhr返回事件感到困惑, _onreadystatechange- > readyState == 4_与onload
之间并没有太大区别,这是真的吗?

var xhr = new XMLHttpRequest();
xhr.open("Get", url, false);
xhr.onreadystatechange = function() {
    if (xhr.readyState === 4)
    {
        /* do some thing*/
    }
};

xhr.send(null);

要么

xhr.onload = function() { /* do something */ }

阅读 536

收藏
2020-05-01

共1个答案

小编典典

应该是同一回事。onload是在XMLHttpRequest 2中添加的,但onreadystatechange自原始规范以来就存在。

2020-05-01