为什么函数request.onreadystatechange被调用两次?

时间:2019-07-17 19:41:05

标签: javascript function rest xmlhttprequest readystate

如何解决?

我尝试过:https://stackoverflow.com/a/13585135/11799442

let request = new XMLHttpRequest();
request.open("GET", "http://localhost:8080", true);
request.onreadystatechange = function () {

    if (request.readyState === 4 && request.status == 200) {
        if (request.onreadystatechange) {

            request.onreadystatechange = null;
             //......
        }
    }
};
request.send();

request.onreadystatechange =函数()

该功能执行两次。不多不少

0 个答案:

没有答案