谷歌地图信息窗口 ajax 加载内容
Google map infowindow ajax load content
我无法从 ajax 调用加载信息窗口数据来自 json 数组这是循环代码...
function getResults(map){
//remove all existing markers
deleteOverlays();
bounds = new google.maps.LatLngBounds();
//set search center
c = map.center;
var cLat = c.lat().toFixed(6);
var cLng = c.lng().toFixed(6);
//get search radius
var radius = $("#radius option:selected").val()
$.ajax({
url:"ajax/search_radius.php?lat="+cLat+"&lng="+cLng+"&radius="+radius,
cache:false,
async:true,
type:"POST",
dataType: "json",
success:function(data){
var l = data.markers.length;//alert(l);
for (i = 0; i < l; i++) {
var point = new google.maps.LatLng(data.markers[i][3], data.markers[i][4]);
var pin = 'images/pins/' + data.markers[i][1] + '.png';
//alert(pin);
marker = new google.maps.Marker({
position: point,
panControl: false,
map:map,
icon:pin
});
bounds.extend(point);
map.fitBounds(bounds);
//add to valid array
markersArray.push(marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.close();
load_content(this,'5');
});
}
}
});
};
这是加载内容的函数
function load_content(marker, id){
$.ajax({
url: 'ajax/get_infowindow_content.php?id='+id,
cache:true,
dataType:"html",
success: function(data){
infowindow.setContent(data);
infowindow.open(map, marker);
}
});
}
我遇到的问题是将标记的 id 传递给函数(上面显示即使显式设置 ID 在运行 php 文件时仍然返回未定义,例如
load_content(this,'5');
我也试过..(除其他变体外)
load_content(this, data.markers[i][0]);
修改为以下内容,其中仍然返回 id 的未定义
google.maps.event.addListener(marker, 'click', function() {
alert (id); //returns undefined
return $.ajax({
type: "POST",
url: "ajax/get_infowindow_content.php?",
data:{
'id':id
},
success: function(data){
infowindow.setContent(data);
infowindow.setOptions({
position: marker.getPosition()
});
infowindow.open(map, marker);
}
});
//infowindow.close();
//load_content(this,'5');
});
试试这个,使用return
return $.ajax({
type: "POST",
url: "url",
data:{
'id':id
},
success: function(data){// function to be called if the request succeeds
infowindow.setContent(data); //set the contents on infowindow
infowindow.setOptions({
position: marker.getPosition()
});
infowindow.open(map, marker);
}
});
相关文章:
- 如何更改jquerymobile中默认的加载ajax加载程序gif
- 无法在 IE6 和 IE7 上加载 ajax
- 页面刷新后重新加载 ajax 检索到的数据
- 清理在加载 Ajax 内容时添加的 CSS
- jquery选项卡加载Ajax内容
- Grails:多个加载ajax调用,但只有一个打印到控制台
- 如何检测通过JSON数据引用的图像何时加载AJAX
- 加载ajax数据时出现jVectorMap问题
- JQuery在加载ajax时阻止链接工作
- 如何在不重新加载ajax的情况下在datatable上.draw()或添加行
- 替换超链接默认操作以加载 AJAX 请求
- 高图表不使用加载 ajax 的数组进行渲染
- 带有 OnClick 的 jQuery 链接标记 href 需要单击两次才能加载 AJAX
- 悬停两次以加载 ajax
- 获取加载 ajax 的文档信息
- 使用 Jquery 在 AJAX 内部加载 AJAX
- 为什么当页面加载 AJAX 时我的 URL 之间没有空格
- 在当前页面中加载一个新的谷歌地图,加载AJAX
- 当滚动达到 80% 时加载 ajax
- 图像滑块未加载 Ajax 请求