Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  85] [ 4]  / answers: 1 / hits: 32580  / 12 Years ago, wed, july 18, 2012, 12:00:00

JSON.stringify(eventObject);



gives:



TypeError: Converting circular structure to JSON






dojox.json.ref.toJson(eventObject);



gives:



TypeError: Accessing selectionEnd on an input element that cannot have a selection.






Is there some library/code ready to use to accomplish it ?


More From » json

 Answers
27

You won't be able to serialize an event object with JSON.stringify, because an event object contains references to DOM nodes, and the DOM has circular references all over the place (e.g. child/parent relationships). JSON can't handle these by default, so you're a bit out of luck there.



I'd suggest to look at How to serialize DOM node to JSON even if there are circular references? which has a few suggestions on how to serialize a DOM node. Also, the following questions seem to have useful information:





JSON libraries able to handle circular references seem to be





Alternatively, you could delete all references to DOM nodes if you don't need them, and then serialize the object. You shouldn't do this after all. See @PointedEars comment :)


[#84170] Tuesday, July 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kenyonmasonc

Total Points: 44
Total Questions: 117
Total Answers: 116

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;