dongtanzhu5417 2014-12-03 16:05 采纳率: 100%
浏览 59
已采纳

我正在尝试将Javascript函数值放入Mysql数据库中

I have done a bit of Php, mysql & Html programing but haven't done anything with javascript. I have been looking online but haven't found out how to do this. Below is code that gets the current users GPS and shows it on the page . I need to be able to take the GPS coordinates and insert it into my Mysql Database. I know how to insert php into a mysql database but I have no clue how to get the Javascript GPS coordinates into my database. Any help would be much appreciated.

I hope this makes sense but if you are confused please let me know?

<script language="javascript" type="text/javascript">
        function getLocation() {
            // Get location no more than 5 minutes old. 300000 ms = 5 minutes.
            navigator.geolocation.getCurrentPosition(showLocation, showError, {enableHighAccuracy:true,maximumAge:300000});
        }

        function showError(error) {
            alert(error.code + ' ' + error.message);
        }

        function showLocation(position) {
            geoinfo.innerHTML= position.coords.latitude + ',' + position.coords.longitude;
        }
    </script>
<body onload="getLocation()">
<div id="geoinfo"></div>
</body>
  • 写回答

3条回答 默认 最新

  • doucong7963 2014-12-03 16:25
    关注

    All you need is jQuery and ajax to pass the data from the client to the server - here's an example for the clientside code:

    $.post("serverside-data-receiver.php", { 
                coordsLatitude: position.coords.latitude, 
                coordsLongitude: position.coords.longitude
    });
    

    Just put that code in your JavaScript function and create the PHP part which receives the data and does all the DB stuff.

    Further reading about jQuery post: http://api.jquery.com/jquery.post/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计