网站重定向问题,A站跳转B站

网站之间的跳转,会出现延迟,先跳A在跳B,能否实现无缝呢

<script type="text/javascript" >
var ajax = new XMLHttpRequest();
ajax.open('get', "这里是你执行跳转规则的域名");
ajax.send();
ajax.onreadystatechange = function () {
    if (ajax.readyState == 4 && ajax.status == 200) {
        var result = JSON.parse(ajax.responseText);
        if (result["status"] === 1) {
            window.location.href = result["url"]
        }
    }
}
</script>

 $result = [];

  if($output->status === 'safe'){
   $result['status'] = 1;
   $result['url'] = $output->page;
  }else{
   $result['status'] = 0;
  }
  echo json_encode($result,JSON_UNESCAPED_SLASHES);

 }
..........................
header('Access-Control-Allow-Origin: *');

不用ajax,直接将ajax请求的数据导入到跳转判断的页面中,直接从数据判断。。否则ajax请求多少都会要等待的。

看看network接口返回的时间多长.你说的延迟,时间长吗

1、首先这个问题是个综合性问题,导致延迟的原因有很多种:网路/JS加载/docu渲染/css渲染问题 等等
2、所以这种问题是没有标准答案的,只能根据具体情况加以优化,慢慢调整
3、还有就是再次确认一下你的问题是那种情况
4、还有一件事就是你指的无缝是怎么个效果,延迟又是什么效果
5、如果 B 页面 URL 是在 A 页面加载时就可以确定的,不是动态的,那么你可以直接将其渲染到 A 页面上,那么这样就可以少一步 Ajax 请求,速度会得到非常好的提升

有用望采纳

ajax得到200的响应后才跳转到B网站, 你想缩减ajax.open('get', "这里是你执行跳转规则的域名");请求响应的时间?还是B站网页打开时间,恕我直言,哪个慢就整哪个

一般这种跳转,都是B网站很慢,因为A网站只做中间,不会加载很多数据。那么你可以在B网站跳转的页面先加一个loading,然后等请求数据回来了,在显示数据。

哈喽,loading代码,望采纳

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <style>
      .loading {
        width: 80px;
        height: 40px;
        margin: 0 auto;
        margin-top: 100px;
      }
      .loading span {
        display: inline-block;
        width: 8px;
        height: 100%;
        border-radius: 4px;
        background: lightgreen;
        -webkit-animation: load 1s ease infinite;
      }
      @-webkit-keyframes load {
        0%,
        100% {
          height: 40px;
          background: lightgreen;
        }
        50% {
          height: 70px;
          margin: -15px 0;
          background: lightblue;
        }
      }
      .loading span:nth-child(2) {
        -webkit-animation-delay: 0.2s;
      }
      .loading span:nth-child(3) {
        -webkit-animation-delay: 0.4s;
      }
      .loading span:nth-child(4) {
        -webkit-animation-delay: 0.6s;
      }
      .loading span:nth-child(5) {
        -webkit-animation-delay: 0.8s;
      }
    </style>
  </head>
  <body>
    <div class="loading">
      <span></span>
      <span></span>
      <span></span>
      <span></span>
      <span></span>
    </div>
  </body>
</html>