-3

如何将帖子数据从 javascript 发送到 php?

我有这个脚本用于在谷歌地图中定位一个点,但是从 post 发送的数据没有显示在 test.php 中。我究竟做错了什么?我需要从 js 文件中获取经度和纬度到 db。谢谢。

pin.php

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="jqPinMyLocation.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('#map_canvas').jqPinMyLocation({
            serverUrl   : 'test.php',//Server url 
            requestType : 'POST', // Type of request that we will send to server
            additionalData : {//Additional data that will be send to server after user drag the cursor
                userid: 2
            },
            address : 'Bucharest, Romania'//You need to provide the default address where the map will be centered
        });
    });
</script>

js文件

var sendNewPositionToServer = function(LatLng) {
    var coordinates = {
        latitude    : LatLng.lat(),
        longitude   : LatLng.lng()
    };
    if( settings.serverUrl !== undefined ) {
        $.ajax({
            url : settings.serverUrl,

            type : (settings.requesttype !== undefined)?settings.requesttype  : 'post',
            data :$.extend(coordinates, settings.additionalData),
            success : function() {

            }
        });
    }
};

最后是我必须发送帖子数据的php文件。

echo $_POST['userid'];
echo $_POST['longitude'];
4

1 回答 1

0

我没有为此使用 JQuery,但我使用

表单数据()

(是一个js函数)用于在发布后使​​用ajax发布数据

于 2013-02-02T11:23:26.160 回答