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!
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.
Comments