【发布时间】:2020-08-07 23:16:59
【问题描述】:
我是 js 的新手,所以我需要一个很好的建议如何解决这个任务。在我看来,它可能看起来像这样,但它肯定不能正常工作:
while (status !== 200) { checkPage(); }
function checkPage() {
var xhr = new XMLHttpRequest(),
method = "GET",
url = link;
xhr.open(method, url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
status = xhr.status;
return true;
}
}
xhr.send();
}
【问题讨论】:
-
为什么要向同一个端点发出多个 GET 请求?这是一个非常糟糕的主意。
-
@terrymorse OP 写道 “在我看来它可能看起来像这样......” 所以我认为它应该被视为伪代码
-
我正在访问的页面有时会抛出204代码,我需要继续尝试直到我得到200,然后重定向到它
标签: javascript jquery ajax