Uncaught TypeError: Converting circular structure to JSON using JSON.stringfy inside Jquery.each

davidwillianx

I created this code to send user invites by websocket but It doesn't work and shows this error:

Uncaught TypeError: Converting circular structure to JSON

$.each(formAttibutes, function(index, formAttribute){
    if (formAttribute[0].value !== 0) {
        if (formAttribute[1].value !== 0) {
            var friend = {
                "name": formAttribute[0],
                "description": formAttribute[1],
            };
            socket.send(JSON.stringify(friend));
        }
    }
});

Oh gosh I'm sleepy, sorry. As you said infinity reference (replace formAttribute[1] >> formAttribute[1].value) thanks!

techfoobar

I think you are looking to have a JSON stringified object containing the values in those elements (and not the elements themselves). For that, you can do:

...

var friend = {
    "name": formAttribute[0].value,
    "description": formAttribute[1].value
};
socket.send(JSON.stringify(friend));

...

Note: The above is assuming formAttribute[0] and formAttribute[1] are DOMElements. If they are jQuery objects, you should use .val() instead.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to solve (Uncaught TypeError: Converting circular structure to JSON)

VM1374:32 Uncaught TypeError: Converting circular structure to JSON(…)

Uncaught TypeError: Converting circular structure to JSON after Angular / dependencies update

Sequelize: TypeError: Converting circular structure to JSON

GraphCool TypeError: Converting circular structure to JSON

"TypeError: Converting circular structure to JSON" with GET request

"TypeError: Converting circular structure to JSON" with GET request

Elliptic : TypeError : Converting circular structure to JSON

Axios TypeError: Converting circular structure to JSON

Angular - TypeError: Converting circular structure to JSON

TypeError: Converting circular structure to JSON in nodejs

avoiding TypeError: Converting circular structure to JSON

TypeError: Converting circular structure to JSON - find error in json

TypeError converting circular structure to json at JSON.stringify (<anonymous>)

Reading fixture is throwing error TypeError: Converting circular structure to JSON

Moving code to an exported function results in TypeError: Converting circular structure to JSON

[Vue warn]: Error in render: "TypeError: Converting circular structure to JSON

Express Middleware: ERROR: TypeError: Converting circular structure to JSON

TypeError: Converting circular structure to JSON in retrieving html string from mongodb

Firestore references create a "TypeError: Converting circular structure to JSON"

Chrome sendrequest error: TypeError: Converting circular structure to JSON

TypeError: Converting circular structure to JSON property 'name' closes the circle

TypeError: Converting circular structure to JSON when trying to POST request

TypeError: Converting circular structure to JSON with StorybookJS on React Native

Doing a proper MongoDB Query (TypeError: Converting circular structure to JSON)

ERROR TypeError: Converting circular structure to JSON --> starting at object with constructor 'FormGroup'

Amazon Cognito confirmPassword fails with (TypeError: Converting circular structure to JSON)

TypeError: Converting circular structure to JSON --> starting at object with constructor 'ClientRequest'

How do I solve "TypeError: Converting circular structure to JSON" in NodeJS