AngularJS error: Transforming circular structure into JSON

My JavaScript function is designed to gather data from a form.

 var dataUpload={};

             dataUpload.p1=$('#p1').combodate('getValue'); //date
             dataUpload.p2=$('#p2').combodate('getValue');//date
             dataUpload.p3=$('#p3').val();                //textarea
             dataUpload.p4=$('#p4').val();                //text input
             dataUpload.p5=Date.now();                    //date  
             dataUpload.p6=1;                             //number
             dataUpload.id=Id;                              //number
           $http.post("url of your route",data).success(function (data)
           {
              console.log("success");
           });

On the first attempt, it triggers an error stating "Converting circular structure to json", but on subsequent attempts, the data is successfully inserted. I am puzzled by this behavior and unsure why it occurs in this manner.

Answer №1

After encountering a common issue, I have come up with a solution: When using a standard $http post or any HTTP method function in AngularJs, the data is sent in JSON format via the toJson() function. However, if the data contains an object that JSON cannot convert, you may encounter the error message 'Converting circular structure to JSON in AngularJs'. In such cases, double-check all values of the data being sent as they may not be what you expect (e.g., expecting a string but getting an object instead). You can determine if your data is an object by logging it to the console:

console.log(data1);  //output : Object obj                             IS AN OBJECT
console.log(data2);  //output : "Answer about it"                      IT'S NOT AN OBJECT

If the output resembles data1, then you need to format your data accordingly using methods like

moment(date).format("YYYY-MM-DD hh:mm:ss")
or utilizing other libraries.

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

Is it possible to reverse hash in a Node.js environment?

After successfully hashing data using the code snippet below, which I obtained from the crypto website, I'm now facing the challenge of reversing the process. How can I convert hashed data back to its original text? const crypto = require('crypt ...

What is causing the chat-widget to display a null value for the style read property?

Could someone assist me with hiding the Widget-chat? I keep getting an error that the property of style is null. Any help would be greatly appreciated. Thank you in advance. document.getElementById("chat-widget").style.display='none'; ...

Customizing the styling of buttons in Highcharts is disabled when in full screen mode

I've integrated highcharts into my Angular application and included a custom button inside the chart to navigate users to another page. However, I encountered an issue when trying to fullscreen the chart using the export menu. The position of the cus ...

I am facing an issue with Angular reactive forms where the default values I set in ngOnInIt are not being reflected

Having some issues with setting default values in my Angular app using reactive forms. The defaults I set in ngOnInit are not showing up. I am also using the filter function within the map method. I am trying to select a value based on the URL and have it ...

Looping Feature in Ionic Framework's Slides Component

Currently, I am working on developing an application using Ionic-Angular. When it comes to incorporating slides in my app, I opted for the ionic 4 ion-slides component. Everything was going smoothly until I wanted to enable looping for the slides so that u ...

how to include extra arguments in json.dump in python2

In my python2 code, I am using json.dump with a custom encoder and I need to pass an additional parameter to the encoder like this: json.dump(data, fp, type, cls=MyEncoder) After reading about it in How to pass parameters to a custom JSONEncoder default( ...

Encountered a login issue when attempting to access the localStorage

Any suggestions on resolving this error? Encountering a QuotaExceededError with DOM Exception 22 This issue arises when attempting to access the localStorage and assign data to the header. Currently working with Angular 2 on the client side using Type ...

Employ Javascript to display a list of all messages sent through Twilio

I'm referencing the Twilio Node.js documentation available at: My goal is to display a list of all messages in the message log for an account. I'm following this example: var accountSid = 'your_sid'; var authToken = "your_auth_token ...

Exploring ways to iterate through an array of objects to extract specific values

Kindly read this information thoroughly before marking it as a duplicate. I currently possess an array of objects as shown below. const filterParams = [ { 'waterfront_type[]': 'Cove' }, { 'area[]': 'Applehead ...

Update the state when a button is clicked and send a request using Axios

Currently in my front end (using react): import '../styles/TourPage.css'; import React, { Component } from 'react'; import axios from 'axios' class TourPage extends Component { constructor(props) { super(p ...

Developing object instances using AngularJS

Looking for some guidance on creating an object using Angular's factory capabilities since I'm new to AngularJS. Here's the code snippet that I have: angular.module('7minWorkout') .factory('WorkoutPlan', function(args){ ...

What happens when tabs are dynamically added on keypress?

I am encountering issues with this code snippet. $('body').on("keypress", ".message", function(e) { if ( e.keyCode == 13 && $(".message").val().length > 0 ) { input = $(".message"); // Check for join com ...

How can I save variable values to a text file or Excel file using Cypress.io?

Is there a way to write the values of a variable on a Text or Excel sheet? I have a variable called tex that stores string values, and I want to output these values onto text files or an Excel sheet if possible. beforeEach(() => { cy.visit('ht ...

What is the best way to incorporate JSON data within a "data:{}" object when making a POST fetch request?

Greetings to all the listeners, this is my first time reaching out for help. I have put together a form and I am making a fetch request to my database system (Xano). Here is a snippet of how my JSON object looks: { "job_type": "full-time& ...

Creating a resizable SVG rectangle element with React

Hey, I'm a beginner in Svg and currently learning ReactJs. I have a question that I'm not sure is possible or not. I have an Svg element with its children wrapped inside a g. The g element contains a rect element that I want to make resizable usi ...

The port is not defined in the express when running with the command "node ."

After going through the tutorial mentioned here, everything was smooth sailing until I reached the part where I had to run the server: https://www.digitalocean.com/community/tutorials/setting-up-a-node-project-with-typescript Attempting to execute the cod ...

How do I transform the date "Tue Nov 26 2019 16:00:00 GMT-0800" into the .NET JSON date format "/Date(1574812800000)/"?

I am looking to convert a date from ISO format to .NET JSON date format using JavaScript. For example, I want to change "Tue Nov 26 2019 16:00:00 GMT-0800" to "/Date(1574812800000)/". ...

Setting MUI input value within a loop using an array value in React JS: A step-by-step guide

Recently, I created a React js demo using React MUI. To handle inputs, I created a separate component called InputText.js for each input field. The issue I encountered is when I tried to use this component to display multiple education fields stored in an ...

Bring JSON files from Amazon S3 into a Postgres RDS database

Looking to create a dynamic script, possibly using lambda, that will automatically upload any new JSON files added to an S3 bucket directly into a PostgreSQL table hosted in RDS. The JSON data is nested and includes lists of JSON objects, making it comple ...

Tips for utilizing JSON responses in various Swift classes

Currently, I am utilizing the swifty.JSON library for parsing JSON data and have successfully obtained the desired output by executing the following code: var outPut = JSON(data: data!) However, my goal is to make this outPut variable global so that I ca ...