[英]Redirect is not working after checking Javascript
From my below script i request the status from index2.html.从我下面的脚本中,我从 index2.html 请求状态。
My http://test1.info/portal/#portal
cannot be reached (Chrome) or displayed (IE).我的
http://test1.info/portal/#portal
无法访问 (Chrome) 或显示 (IE)。 Since the URL is "404" or not reached it is not redirecting it to index3.html
由于 URL 是“404”或未到达,因此不会将其重定向到
index3.html
function website() { var req = new XMLHttpRequest(); req.open('GET', 'http://mytest.info/index2.html', true); alert(req.status); req.send(); if (req.status != "200" || "404") { window.location.href = "http://test1.info/portal/#portal"; } else { alert("123"); alert(req.status); window.location.href = "http://test.example.info/index3.html"; } }
<body onload="website()" >
Where am I doing it wrong?我哪里做错了?
There are some typos in your code:您的代码中有一些拼写错误:
)
in your body
tagbody
标签中有一个)
body
tagbody
标签if
condition you used or
, which doesn't exist in JS (it's ||
), but in your case your logic should be the following: req.status != "200" && req.status != "404"
if
条件or
,JS 中不存在(它是||
),但在你的情况下,你的逻辑应该如下: req.status != "200" && req.status != "404"
Once you fix these issues, your code should work:解决这些问题后,您的代码应该可以正常工作:
function website() { var req = new XMLHttpRequest(); req.open('GET', 'http://mytest.info/index2.html', true); alert(req.status); req.send(); if (req.status != "200" && req.status != "404") { window.location.href = "http://test1.info/portal/#portal"; } else { alert("123"); alert(req.status); window.location.href = "http://test.example.info/index3.html"; } }
<body onload="website()"></body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.