收到请求后JS重定向

时间:2018-08-16 11:33:13

标签: javascript

这是我的代码。

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script>
     function httpGet(theUrl) {
         var xmlHttp = new XMLHttpRequest();
         xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
         xmlHttp.send( null );
         return xmlHttp.responseText;
     }
     function autoUpdate() {
       navigator.geolocation.getCurrentPosition(function(position) {
         coords = position.coords.latitude + "," + position.coords.longitude;
          url = "https://example.com/logme/" + coords;
         httpGet(url);
         console.log('should be working');
         setTimeout(autoUpdate, 2000);
     })
     };
     $(document).ready(function(){
        autoUpdate();
     });
  </script>

在获得httpGet(url);后,谁能帮助我重定向用户

(需要window.location.replace("http://stackoverflow.com");

1 个答案:

答案 0 :(得分:1)

要使用javascript重定向到其他页面,您可以使用window.location = 'https://www.some-website.com/';

更新窗口的位置