未捕获RangeError:最大调用堆栈大小超过ajax谷歌地图

时间:2017-04-25 11:03:22

标签: javascript ajax google-maps

有人可以提供帮助

我正在做一个谷歌地图项目绘制形状(圆形,多边形,矩形等)并将其保存到数据库以便稍后重新加载 为了保存例如一个圆圈,我正在这样做:

if (event.type === 'circle') {

  CIRCLES.push({
    "centerLat": event.overlay.center.lat(),
    "centerLng": event.overlay.center.lng(),
    "radius": event.overlay.radius,
    "fillColor": event.overlay.fillColor,
    "fillOpacity": event.overlay.fillOpacity,
    "strokeWeight": event.overlay.strokeWeight,
    "zIndex": event.overlay.zIndex
  });

  var cirlceArea = Math.PI * Math.pow(event.overlay.radius, 2);
  var circleInfoWindow = new google.maps.InfoWindow({
    content:'<h5>Circle Area</h5><b>'+cirlceArea +'M²</b>',
    position:event.overlay.center,
    map:map
  });
  // circleInfoWindow.setMap(map);
  // circleInfoWindow.open(map);

  infoWindowArr.push(circleInfoWindow);

到目前为止代码工作正常但是当我使用jquery ajax提交数据时它会触发此错误Uncaught RangeError:超出最大调用堆栈大小 但是当我评论这行代码时infoWindowArr.push(circleInfoWindow); 它工作正常 最后,这是我的ajax

$("#map-form").on("submit", function (e) {
e.preventDefault();
$.ajax({
  type: 'POST',
  dataType: 'json',
  url: '/dash/store',
  data: {
    "circles": CIRCLES,
    "polygons": POLYGONS,
    "rectangles":RECTANGLES,
    "polylines":POLYLINES,
    "projectName":projectName,
    "description":description,
    "infoWindow":infoWindowArr, 
    /*'captcha':grecaptcha.getResponse()*/
  }

我在这里查看了许多类似的问题,但没有找到解决方案 我认为它来自ajax请求 谢谢你

1 个答案:

答案 0 :(得分:0)

我的猜测是jQuery在请求参数中的“data”对象上调用JSON.stringify,并且图中有一个循环(它进入无限递归)。因此,不要推送circleInfoWindow对象(其中包含对地图的引用),只需按下相关参数,如:

infoWindowArr.push({
   content:'<h5>Circle Area</h5><b>'+cirlceArea +'M²</b>',
   position:event.overlay.center,
});