无法解决';未定义的索引';ajax帖子出错


Cannot solve 'Undefined Index' error with ajax post

我知道这个问题已经被问了很多次,但我几乎浏览了所有提出的解决方案,但似乎都不起作用。首先,这是我的文件结构:

index.php
-js
  map.js
-css
  main.css

以下是我要做的:我使用谷歌地图API,我在地图上的不同位置放置了许多标记。当用户单击其中一个标记时,我希望将一个特定的变量提交到index.php,以便在SQL查询中使用它。这是我的代码:

map.js

google.maps.event.addListener(marker, 'click', (function(marker, i) {
     return function() {
        var place = 1234;
        // $.post('/index.php',{'place' : place},function(data,status){alert(status)});
        $.ajax({
            type:"POST",
            url: '/index.php',
            data: "place="+place,
            success: function(data,status){
                alert(status)
            }
        });
     }
})(marker, i));

index.php

<?php
    if (isset($_POST["place"])) {
       echo ($_POST["place"]);
    }
?>

我在我的:中引用了那些jQuery库

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />

我尝试了所有可能的语法更改,但它已经困扰了我好几天了。

索引文件在上层目录中,您必须更改

url: '/index.php',

url: '../index.php',