Javascript 无法解决';未定义索引';ajaxpost错误
我知道这个问题已经被问过很多次了,但我几乎把所有提出的解决方案都看了一遍,似乎都不管用。首先,这是我的文件结构:Javascript 无法解决';未定义索引';ajaxpost错误,javascript,php,jquery,ajax,google-maps,Javascript,Php,Jquery,Ajax,Google Maps,我知道这个问题已经被问过很多次了,但我几乎把所有提出的解决方案都看了一遍,似乎都不管用。首先,这是我的文件结构: index.php -js map.js -css main.css 以下是我想做的: 我使用谷歌地图API,我在地图上的不同位置放置了许多标记。当用户单击其中一个标记时,我希望将一个特定变量提交到index.php,以便在SQL查询中使用它。这是我的代码: map.js index.php 我在我的中引用了这些jQuery库: <script src="http
index.php
-js
map.js
-css
main.css
以下是我想做的:
我使用谷歌地图API,我在地图上的不同位置放置了许多标记。当用户单击其中一个标记时,我希望将一个特定变量提交到index.php,以便在SQL查询中使用它。这是我的代码:
map.js
index.php
我在我的中引用了这些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',
到
你看过浏览器控制台中的请求/响应了吗?更简单的
google.maps.event.addListener(marker,'click',function(){var place=1234;$.post('/index.php',{place':place},function(data){alert(data)})})
@JayBlanchard-It-post;然后GET@mplungjan尝试了这个方法,但没有成功,直到没有希望,它返回了一个成功,所以我假设它成功地发布到url,但是它没有在php代码中设置变量“place”。try而不返回google.maps.event.addListener(marker,'click',(function(marker,I){//return function(){var place 1234;$.ajax({type:'POST',url:'/index.php',data:'place=“+place,success:function(data,status){alert(status)}}};//}}(marker,i));
<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',