使用ajax加载谷歌地图api时出现错误


Error when using ajax load google map api

我有一个文件index.php使用jquery:

<div id="nav"><a href="#"><input type="hidden" value="36.753671,-119.768336" />test</a></div>
<script type="text/javascript">
$(document).ready(function(){
    $('#nav a').click(function() {
        var id = $(this).find('input:hidden').val();
        var dataString = 'id='+id;
        $.ajax({
           type: 'POST',
           url: 'map.php',
           data: dataString,
           cache: false,
           success: function(html) {
                $('.map').html(html);
           } 
        });
    });
});
<div class="map"></div>
在map.php

$id = $_POST['id'];
    <script src="http://maps.google.com/mapsfile=api&amp;v=2&amp;sensor=true_or_false&amp;key=ABQIAAAA" type="text/javascript"></script>
    <body onload="initialize()" onunload="GUnload()">
        <div id="map_canvas" style="width: 200; height: 200px"></div>
    </body>
    <script type="text/javascript">
    function initialize() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(<?php echo $id ?>), 16);
            map.setUIToDefault();
        }
    }
    </script>

当我输入input id=('36.753671,-119.768336')是ajax不结果,我能帮忙吗?我想要这个想法

我看到map.php中的脚本片段在PHP代码中,而不应该在PHP代码中。有两种解决方法。1)

$id = $_POST['id'];
?> //close php tag here
    <body onload="initialize()" onunload="GUnload()">
        <div id="map_canvas" style="width: 200; height: 200px"></div>
    </body>
    <script type="text/javascript">
    function initialize() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(<?php echo $id ?>), 16);
            map.setUIToDefault();
        }
    }
    </script>

2)

$id = $_POST['id'];
   echo '<script src="http://maps.google.com/mapsfile=api&amp;v=2&amp;sensor=true_or_false&amp;key=ABQIAAAA" type="text/javascript"></script>
    <body onload="initialize()" onunload="GUnload()">
        <div id="map_canvas" style="width: 200; height: 200px"></div>
    </body>
    <script type="text/javascript">
    function initialize() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(<?php echo $id ?>), 16);
            map.setUIToDefault();
        }
    }
    </script>';