我正在使用以下代码来查找浏览器位置并将其发布到下一页,但问题在于JavaScript花费很少的时间来查找浏览器位置并且表单正在发布之前浏览器位置被找到了,我怎么才能让表单提交后才能找到浏览器位置?JavaScript检查值是否退出,然后提交表单
newtest1.php
<html>
<head>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function showPosition(position) {
document.getElementById("getlat").value = position.coords.latitude;
document.getElementById("getlon").value = position.coords.longitude;
}
getLocation();
</script>
</head>
<body>
<form id="myForm" method="post" action="newtest2.php">
<input type="text" id="getlat" name="getlat" />
<input type="text" id="getlon" name="getlon" />
<input type="button" name="myformer" onclick="myFunction();" />
</form>
<script>
function myFunction() {
document.getElementById("myForm").submit();
}
myFunction();
</script>
</body>
</html>
newtest2.php
<?php
echo $_POST['getlat'];
echo $_POST['getlon'];
?>
你为什么要对这个问题提出一点问题? http://stackoverflow.com/questions/25539213/passing-values-from-javascript-to-php-using-ajax – 2014-08-28 01:56:49
@PrabowoMurti - 如果你阅读这两个问题,你会明白代码是相同的,但问题是不同。 – lock 2014-08-28 02:01:03
你总是可以编辑和改进你以前的问题 – 2014-08-28 02:02:11