动态加载的jquery手风琴中的Google Maps [英] Google Maps within a dynamically loaded jquery Accordion

查看:58
本文介绍了动态加载的jquery手风琴中的Google Maps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ajax加载的内容在jquery ui手风琴中加载google map.

I'm trying to load a google map within a jquery ui accordion with contents loaded by ajax.

 $("h2", "#accordion").click(function(e) {
  var contentDiv = $(this).next("div");
  if (contentDiv.children().length == 1)
  {
   contentDiv.load($(this).find("a").attr("href"));
   contentDiv.ready(function(){
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
     zoom: 8,
     center: latlng,
     mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
   })
  }
 });

这是我当前的代码(Google Maps API V3),但是当我当前单击时,它重定向到href的网址,显然没有google map,因为此响应中没有JavaScript.如果我注释掉地图行,则一切正常(除了地图本身).

That's my current code (Google Maps API V3), but it redirects to the url of the href when I click currently, obviously with no google map because there's no javascript in this response. If I comment out the map line everything works fine (except the map itself).

推荐答案

直到现在我还没有想到,但是由于每个手风琴的内容都是动态加载的,因此构成了非法的跨站点请求.该地图必须从我自己的Web服务器上获取,并传输到手风琴中的ajax请求,或者Google地图必须一次加载并操纵到正在加载的手风琴窗格中.

It didn't occur to me until now, but since the content of each accordion is dynamically loaded, this constitutes an illegal cross site request. The map must be obtained from my own web server and transmitted to the ajax request in the accordion or the google map must be loaded once and manipulated into the dom of the accordion panes being loaded.

这篇关于动态加载的jquery手风琴中的Google Maps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆