簡體   English   中英

無法使用ajax將Google地圖從頁面加載到另一個頁面中的div

[英]Unable to load Google map from a page into a div in another page using ajax

我正在嘗試使用此JavaScript將一個html頁面加載到另一個html頁面


$('.myajax').click(function() {
    var myhref=$(this).attr('href');
    $('#contentdiv').hide().load(myhref).fadeIn('slow');
    return false;
});

每當我嘗試將Google Map加載到名為contentdiv div中時,就會出現問題。 每當我嘗試這樣做時,瀏覽器上都不會顯示任何內容; 它完全空白。 包含Google地圖的頁面如下:


<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Google Maps Geocoding Demo</title> 
   <script src="http://maps.google.com/maps/api/js?sensor=false" 
           type="text/javascript"></script> 
</head> 
<body> 
   <div id="map" style="width: 400px; height: 300px;"></div> 
   <script type="text/javascript"> 
   var address = 'London,UK';
   var map = new google.maps.Map(document.getElementById('map'), { 
       mapTypeId: google.maps.MapTypeId.ROADMAP,
       zoom: 6
   });

   var geocoder = new google.maps.Geocoder();
   geocoder.geocode({
      'address': address
   }, 
   function(results, status) {
      if(status == google.maps.GeocoderStatus.OK) {
         new google.maps.Marker({
            position: results[0].geometry.location,
            map: map
         });
         map.setCenter(results[0].geometry.location);
      }
      else {
         // Google couldn't geocode this request. Handle appropriately.
      }
   });

   </script> 
</body> 
</html>

有人可以指出錯誤??


當你使用$.load()它會加載所有輸出的數據,因此你在<head>中沒有加載任何內容,你沒有加載谷歌地圖api,也沒有加載javascript,至少不是以它可以處理的方式加載我想想,從來沒有嘗試過,但它的定義並不是$ .load()的用途。

你必須使用iframe或嘗試實際包含谷歌地圖庫,並在實際頁面中運行javascript代碼,包括谷歌地圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM