I am currently working with fullCalendar scheduler where I need to drag & drop external events. Here when I am creating a new external event I need to save its data as a JSON string into the localStorage. while page loading I am reading the localStorage and if data is there I need to show the external events in the external drop box from where I can drag them and drop into the calendar. But I am getting "VM872:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1" while trying to parse the JSON string that I stored in localStorage. Below is my code
var extEvent = localStorage.getItem("externalEvents");
console.log(extEvent);
if(extEvent) {
var parsedItem = JSON.parse(extEvent);
//var parsedItem = JSON.parse(JSON.stringify(extEvent));
//var parsedItem = extEvent;
$.each(parsedItem, function(i, item) {
var elem = $( "<div class='external-dropable-event fc-event'>" ).appendTo( '#external-events-listing' ).text( item.title );
elem.draggable({
helper: function(ev) {
return $(ev.target).clone().css({
width: $(ev.target).width()
});
},
zIndex: 9999,
revert: true,
revertDuration: 0
});
var extEventData = { title: item.title, pid : item.pid, tid: item.tid, duration: item.duration, trName: item.trName, location: item.location, stick: item.stick };
elem.data('event', extEventData);
});
}
Unfortunately I am getting this error in google chrome. This code works fine with Fire Fox.
I tried to parse the stored data as var parsedItem = JSON.parse(JSON.stringify(extEvent)) also. But this fires a "Uncaught TypeError: Cannot use 'in' operator to search for '14' in [object Object]" in both chorme as well as firefox.