Error: The call stack size has been exceeded while using Ajax Google Maps, resulting in a RangeError

Can you assist me?

I am currently working on a project involving drawing shapes (circles, polygons, rectangles, etc.) on Google Maps and saving them to the database for future reference. To save a circle, I have implemented the following code:

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
  });
  
  infoWindowArr.push(circleInfoWindow);

The code works fine until I try to submit the data using jQuery ajax, at which point it triggers an error: Uncaught RangeError: Maximum call stack size exceeded. Interestingly, when I comment out the line

infoWindowArr.push(circleInfoWindow);
, everything works without any issues. Here is the relevant AJAX snippet:

$("#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
  }

I have searched through similar questions but have yet to find a solution. I suspect the issue may be related to the AJAX request. Any assistance would be greatly appreciated. Thank you.

Answer №1

One possible explanation could be that jQuery is using JSON.stringify on the "data" object within the request parameters, causing a cyclic reference in the graph leading to infinite recursion. A solution might involve not pushing the circleInfoWindow object (which contains references to the map and others), but rather just push the necessary parameters like this:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fetch initial data, then refresh upon completion (using Django or ajax)

My webpage is loading very slowly because it needs to fetch over 50 objects from the database. I want to optimize this process by initially loading only the first 10 results, allowing the server to fetch the rest in the background, and then refreshing the ...

Leveraging async/await within a React functional component

Just getting started with React for a new project and facing challenges incorporating async/await functionality into one of my components. I've created an asynchronous function called fetchKey to retrieve an access key from an API served via AWS API ...

Why is it that Object.getOwnPropertyDescriptors does not function on HTMLElements?

Upon traversing the prototype chain, one would expect to find Object.prototype at the bottom (or top?), leading to the assumption that they would function like typical objects. However, when using Object.getOwnPropertyDescriptors, the properties obtained d ...

Error Encountered - Uncaught Error: $.ajax Function Not Found

I've come across various questions and answers regarding this issue, but none have been able to provide a solution. My goal is to use jQuery to make an AJAX call in order to retrieve an IP address. Every time I run the code below, I encounter Uncaugh ...

Unable to execute an Ajax post to a PHP file located in a specific directory

Struggling with an Ajax request for a project, I've encountered some errors along the way. Occasionally, I receive an Error 500 (Internal Server Error), but eventually managed to get everything working smoothly until I attempted to move my scripts int ...

Tips for transferring JSON data to a CodeIgniter view

I have a query regarding how to replace a specific section of my webpage with data returned from the controller. Currently, I have a page that displays movie details directly fetched from the database. My goal is to only display movies of a particular genr ...

Troubleshooting problems with AJAX in WordPress

I have been attempting to transfer an array from PHP to JavaScript in order to display search results from a database. After converting the array into JSON format, I am facing difficulties in retrieving it. Despite having colleagues experienced in AJAX, we ...

Converting a JavaScript string containing an `import` statement into a browser-compatible function

Can my vue application transform the given string into a callable function? const test = 'import { pi } from "MathPie"; function test() { console.log(pi); } export default test;' The desired output format is: import { pi } from "M ...

Vue PWA - manifest.json replaced upon refreshing the page

I'm encountering an issue with my Progressive Web App (PWA) where reloading the page manually or redirecting using window.location results in the manifest.json file being overwritten with the contents of index.html. This leads to an error stating Mani ...

Adjust the margin of a child div based on the parent's width, with the use of JavaScript

Currently, I am developing a website at and I am interested in replicating the layout of another site. The site I would like to emulate is , which features multiple sections with child divs that have margins around them. In order to achieve this effect o ...

SignalR blocking axios requests (In a Waiting State)

I am currently developing a project that involves bidding on products in Auctions with real-time updates of the bid price. With potentially thousands or even millions of users worldwide participating in the bidding process. We have implemented SignalR for ...

What is the reason for this MongoDB document consistently having the identical nanoid?

Although I've managed to find a solution, my main concern is understanding the root cause of the bug. In the scenarios below, MongoDB documents are being created with identical id and date values respectively. id: { type: String, required: tru ...

chart for visualizing two rows with matching IDs and dates

I have been attempting to accomplish the following two scenarios: 1) When both ID and dates are the same in the chart, but the descriptions differ, I want to display them on separate lines. 2) If there is not enough room to show the row label, I would li ...

Execute a function upon the invocation of a different function

I am exploring how to trigger a function when another function is executed. While addEventListener is typically used for events like "click" or "mouseover", I am looking to detect when a function is called. For instance: Function 1 is invoked, an ...

Tips for modifying the style of a DOM element using AngularJS

A new function was developed called validateCode() which executes when a user interacts with the button. The objective is to modify the height of the <div class="loginForm"> </div> upon clicking the button. One attempt has been made at: http: ...

Only the test cases that passed were documented in Mochaweasome

Currently, I am utilizing the mochawesome report to document my cypress execution. The test case is displaying a simple pass without providing details about the steps taken or the assertions made in the report. Sample snapshot (Apologies for the excessive ...

Is there a way to create a popover menu in VueJS without using JQuery

I found exactly what I need in this helpful answer. It demonstrates a menu appearing when clicking on a table row. The dilemma is that it relies on JQuery... Therefore, I am curious if achieving the same functionality without JQuery is possible. Maybe thr ...

What is the best way to divide a string that contains n concatenated JSON strings in JavaScript or Node.js?

Imagine I receive the following string from a socket server (which is out of my control): {"data":{"time":"2016-08-08T15:13:19.605234Z","x":20,"y":30}}{"data":{"time":"2016-08-08T15:13:19.609522Z","x":30,"y":40}} Because it contains 2 JSON strings, using ...

Patience is key when letting AJAX calls complete their execution in jQuery functions

In each of my 3 functions, I have a synchronous AJAX call. Here is an example: function() { a(); b(); c(); } a() { ajaxGet(globals.servicePath + '/Demo.svc/GetDemoList/' + sessionStorage.SessionId,function(data, success) {}, '&apos ...

Display image once form has been submitted

The page I have consists of the following code: HTML CODE <table border="0" cellspacing="1" cellpadding="1" id="echipajucator" title="Echipa Jucator"> <tr> <th><div align="left"><span>Team</span></div> ...