简体   繁体   中英

JS redirect after got request

Here is my code.

 <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>

can anyone helps me redirect user after I got httpGet(url);

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

要使用 javascript 重定向到不同的页面,您可以使用window.location = 'https://www.some-website.com/';更新窗口的位置window.location = 'https://www.some-website.com/';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM