我有一个部分视图,它进行ajax调用以从其他部分视图中获取内容。我能够查看原始数据但无法加载地图内容。我认为ajax的加载速度比地图快,所以地图没有显示出来。请给我一个答案!!!
$.ajax({
type: 'GET',
url: '@Url.Action("Detail", "Location")',
datatype:"html",
success: function (data) {
$('#loc').html(data);
},
error: function () {
alert('AJAX Failure!');
}
});
我有控制器加载局部视图
[HttpGet]
public ActionResult Detail()
{
return PartialView("_Details", ViewModel);
}
在局部视图中,我有一张微软地图和一些原始文本。
<script type="text/javascript">
$(document).ready(function () {
var map = null;
var infobox = null;
function GetMap()
{
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById("myMap"),
{credentials:"Bing Maps Key"});
// Retrieve the location of the map center
var center = map.getCenter();
// Create a pin at the center of the map and its corresponding infobox
var pin = new Microsoft.Maps.Pushpin(center);
infobox = new Microsoft.Maps.Infobox(center, {title: 'Pushpin infobox', visible:false, offset:new Microsoft.Maps.Point(0,35)});
// Add event handlers for hovering over the pushpin
Microsoft.Maps.Events.addHandler(pin, 'mouseover', showInfobox);
Microsoft.Maps.Events.addHandler(pin, 'mouseout', hideInfobox);
// Add the pushpin and hidden infobox to the map
map.entities.push(pin);
map.entities.push(infobox);
}
function showInfobox()
{
infobox.setOptions({visible:true});
}
function hideInfobox()
{
infobox.setOptions({visible:false});
}
GetMaps();
});
</script>