我的代码不在服务器上运行,但在本地主机上运行

时间:2019-05-19 19:36:55

标签: javascript

Code not working on server want to find geo-location and store into database

  

无法在服务器上运行的代码想查找地理位置并将其在w3school code.的本地主机上正常运行的数据库存储到数据库中

<!DOCTYPE html>
<html>
<body>

<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  window.location = "position/?latitude="+position.coords.latitude+"&longitude="+position.coords.longitude;
}
</script>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

服务器上没有地理位置库。 navigator.geolocation仅存在于浏览器中。