Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查Javascript后重定向不起作用_Javascript_Html - Fatal编程技术网

检查Javascript后重定向不起作用

检查Javascript后重定向不起作用,javascript,html,Javascript,Html,从下面的脚本中,我从index2.html请求状态 我的http://test1.info/portal/#portal无法访问(Chrome)或显示(IE)。由于URL为“404”或未到达,因此不会将其重定向到index3.html 功能网站(){ var req=新的XMLHttpRequest(); 请求打开('GET','http://mytest.info/index2.html",对),; 警报(请求状态); 请求发送(); 如果(请求状态!=“200” || "404") { w

从下面的脚本中,我从index2.html请求状态

我的
http://test1.info/portal/#portal
无法访问(Chrome)或显示(IE)。由于URL为“404”或未到达,因此不会将其重定向到
index3.html

功能网站(){
var req=新的XMLHttpRequest();
请求打开('GET','http://mytest.info/index2.html",对),;
警报(请求状态);
请求发送();
如果(请求状态!=“200”
|| "404") {
window.location.href=”http://test1.info/portal/#portal";
}否则{
警报(“123”);
警报(请求状态);
window.location.href=”http://test.example.info/index3.html";
}
}

您的代码中有一些拼写错误:

  • 您的
    正文中有一个
  • 您尚未关闭
    正文
    标记
  • if
    条件中,您使用了
    ,这在JS中是不存在的(它是
    |
    ),但在您的情况下,您的逻辑应该如下:
    req.status!=“200”和需求状态!=“404”
  • 一旦您解决了这些问题,您的代码应该可以工作:

    功能网站(){
    var req=新的XMLHttpRequest();
    请求打开('GET','http://mytest.info/index2.html",对),;
    警报(请求状态);
    请求发送();
    如果(请求状态!=“200”和&req.status!=“404”){
    window.location.href=”http://test1.info/portal/#portal";
    }否则{
    警报(“123”);
    警报(请求状态);
    window.location.href=”http://test.example.info/index3.html";
    }
    }

    还是
    ?这是什么语言?始终检查错误控制台…@CristianTraìna这是一个示例对不起,代码中的输入错误,我已经更正并尝试了,但我仍然转到test1.info。虽然url不可访问,但我正在登录此url。接收请求状态0如果
    req.status
    为0,则必须检查控制台:)我在控制台上检查时发现未定义