Javascript JS在收到请求后重定向
这是我的密码Javascript JS在收到请求后重定向,javascript,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 );
<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(theUrl){
var xmlHttp=new XMLHttpRequest();
open(“GET”,theUrl,false);//对于同步请求为false
xmlHttp.send(空);
返回xmlHttp.responseText;
}
函数自动更新(){
navigator.geolocation.getCurrentPosition(函数(位置){
坐标=position.coords.latitude+“,”+position.coords.longitude;
url=”https://example.com/logme/“+协调;
httpGet(url);
console.log('应该正在工作');
设置超时(自动更新,2000);
})
};
$(文档).ready(函数(){
自动更新();
});
在我得到httpGet(url)后,有人能帮我重定向用户吗代码>
(需要window.location.replace(“http://stackoverflow.com”;
)若要使用javascript重定向到其他页面,可以使用window.location='1'更新窗口的位置https://www.some-website.com/';代码>请告诉我们您问题中的确切问题。=>在你告诉我你的位置后,我需要重定向。>在你允许我你的位置后,我需要重定向。这就是回调函数在getCurrentPosition
中的作用。这会让你知道用户已经响应了请求-(你能给我一些作品代码或例子吗?请阅读。