我想从控制器操作(返回局部视图)向InfoWindow显示内容。当我点击Mraker时,它会在infowindow中显示“Undefined”。
如何将局部视图渲染到谷歌地图InfoWindow?
function AjaxDisplayString() {
var addressData;
var testData;
$.ajax({
type: "GET",
url: '/Account/Tooltip',
dataType: "HTML",
contentType: 'application/json',
traditional: true,
data: addressData,
success: function (result) {
debugger;
return result
},
error: function (arg) {
alert("Error");
}
});
}
var infowindow = new google.maps.InfoWindow({
content: "<div>"+ AjaxDisplayString() + "</div>"
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
答案 0 :(得分:0)
AjaxDisplayString是ajax调用,因此结果很晚才到达但你倾向于立即打开infowindow。修改下面的调用,它将起作用。
var infowindow = new google.maps.InfoWindow({
content: "";
});
function AjaxDisplayString() {
var addressData;
var testData;
$.ajax({
type: "GET",
url: '/Account/Tooltip',
dataType: "HTML",
contentType: 'application/json',
traditional: true,
data: addressData,
success: function (result) {
debugger;
infowindow.setContent("<div>"+ result + "</div>");
infowindow.open(map, marker);
},
error: function (arg) {
alert("Error");
}
});
}
google.maps.event.addListener(marker, 'click', function () {
AjaxDisplayString(map, marker)
});