2
votes

I'm trying to make an update by http call on fullcalendar drop event but getting "TypeError: Converting circular structure to JSON at Object.stringify (native)" error.

this is the client side code:

    drop: function() {
       $scope.schedule.tmpevents = $scope.schedule.events;
        $http.put('/api/schedules/updatetemp/' + $scope.schedule._id, $scope.schedule).success(function(){
          alert("temp schedule updated");
        });   
     },

server side code:

exports.updatetemp = function(req, res) { 
  Schedule.update({_id: req.params.scheduleid}, {$set: {tmpevents: req.body.tmpevents}}, function(err, result){
    if (err) { 
      console.log(err); 
      return handleError(res, err); 
    } 
    return res.status(200).json(result); 
  });
};

the very same code works when I call it after the update button click and it updates the temp events but when I call it at the end of a function but when it's called from fullcalendar's drop event it gives out this error. I appreciate any help..

1
Is $scope.schedule your event? - tymeJV

1 Answers

0
votes

The reason of the error basically comes from things such as:

var a = { 'b': 'c' };
var c = { 'd': a };
JSON.stringify(c); //will cause error

Javascript engine tries to transform object to string and goes deeper and deeper without possiblity to end the process.

You should find the place where the recursion occurs and remove them (you should bring them back after you created request) or send only some of the items instead of whole event.