0

Im executing a webpage but it displaying following error while checking it on Console. 'Uncaught TypeError: Converting circular structure to JSON'

console.log(JSON.stringify(physicianInfo));
 Ext.Ajax.request(
   { async : true, 
     url : Global.URLPrefix + 'addPhysicianInformation', 
     method : 'GET', 
     params : { 
         physicianInfo : JSON.stringify(physicianInfo), callFrom : 'add' },
     success : function (request, resp) { 
         var physician1 = Ext.decode(request.responseText); console.log(physician1);
Tim B
  • 40,716
  • 16
  • 83
  • 128
  • Check the data that's returned from the ajax call and add it to your question. – Stefan Gehrig Jan 03 '14 at 13:16
  • What is that `physicianInfo` object that you are stringifying? Apparently it contains itself. Log it without trying to stringify it, otherwise you're getting the error already there. – Bergi Jan 03 '14 at 13:29

2 Answers2

5

This happens when you have a circular reference between objects.

For example:

A references B
B references A

When you try and serialize A then it needs to serialize B, but then it needs to serialize A again and there is no way to represent that loop in JSON. The result would be an infinite recursive loop.

You need to identify and remove the circular references. Remember that the chain can be more complex than the above:

A references B
B references C
C references A

It doesn't matter how many links there are or how they are stored. If you can go from one object to another object and then back to the first one by any route then it is a circular reference.

Tim B
  • 40,716
  • 16
  • 83
  • 128
  • this is my code: console.log(JSON.stringify(physicianInfo)); Ext.Ajax.request({ async : true, url : Global.URLPrefix + 'addPhysicianInformation', method : 'GET', params : { physicianInfo : JSON.stringify(physicianInfo), callFrom : 'add' }, success : function (request, resp) { var physician1 = Ext.decode(request.responseText); console.log(physician1); –  Jan 03 '14 at 12:29
  • 1
    Inside your physicianInfo object (which you haven't posted) probably. You should add the code to the question not as a comment (I did it for you this time). Beyond that if you want me to write your code for you my contracting rates are very reasonable... – Tim B Jan 03 '14 at 13:30
-3

JSON can't contain circular references (do you know what a circular reference is?)

You'll need to reformat your data structure to avoid them before serializing.

johnnycardy
  • 3,049
  • 1
  • 17
  • 27