【发布时间】:2016-04-24 18:04:23
【问题描述】:
我可以知道我的代码有什么问题吗?无论 url 链接是否可用,它都会返回 0。
<Script>
function doSomethingIfFound(url, status) {
alert(url + " was found, status " + status);
}
function doSomethingIfNotFound(url, status) {
alert(url + " was not found, status " + status);
}
function test(url) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
doSomethingIfFound(url, xhttp.status);
} else if (xhttp.readyState == 4 && xhttp.status != 200) {
doSomethingIfNotFound(url, xhttp.status);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
test("https://test.e-cover.com.my/");
test("https://www.e-cover.com.my/");
test("http://www.mypolicy.com.my/mypolicy/login.jsp/");
test("https://itdidnotexistwhenitrieitiswear.museum/");
</script>
【问题讨论】:
标签: javascript html hyperlink xmlhttprequest