Calling JSON.stringify error for complex object in Safari

As stated this happens in Safari while in Chrome and Firefox it's working fine.

I think it's because the object that's turned into json has two properties that contain a moment object. I changed them to date object and the stringify function passed.

The strange thing is that if I try doing JSON.stringify(moment()) it is working, so I am not sure how to debug this and find where the issue is.

Here is a screenshot of the error in Safari:



After some debugging I noticed that this error happens after a dhtmlxwindow onclose event. I load a partial view in a dhtmlx window and in there I create this object which gets pushed into a list intialized into the parent view before closing the window.

Before I close the window I do JSON.stringify(parent.addedContracts) and it's working fine after the onclose event happens (I don't have override code there) the list has that same object (I checked all properties) but the stringify fails for the same list.


Creation of the object that's get added to the list goes like this:

var contractStartDate = moment(contractStartDateCalendar.getDate(true), "L");
var contractEndDate = moment(contractEndDateCalendar.getDate(true), "L");

var newContract = {
    Id                  : uniqueId,
    FunctionDesc        : $("#contractFunction").val(),
    ContractHours       : $("#contractHours").val(),
    AdditionalCostFactor: $("#contractAdditionalCostFactor").val().replace(',', '.'),
    VacationFormula     : contractHolidayCostFactor,
    StartDate           : contractStartDate,
    EndDate             : contractEndDate,
    Notes               : Encoder.htmlEncode(tinyMCE.get('contractNotes').getContent()),
    DaysOfWeek          : workingDaysString,
    PlusMinus           : $("#contractTypeDropdown option:selected").data("plusminus"),
    SalaryCalculation   : $("#contractTypeDropdown option:selected").data("salarycalculation"),
    ContractTypeId      : $("#contractTypeDropdown").val(),
    ContractTypeName    : $("#contractTypeDropdown option:selected").text(),
    UploadedImageUrl    : uploadedSignedContractUrl


After this line the JSON.stringify is ok, but when the close event happens on the dhtmlxwindow something changes and the stringify fails.



Regardless of your implementation (and since I can't check an example of your code that works in Safari but fails in Chrome), if you think the implementation of JSON is at fault in Safari, consider using a JSON polyfill

As for future questions, please consider showing us minimal examples of what is not working. Not only will this possibly reveal the answer you were seeking, if it doesn't it will make it easier for us to depict the problem.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.