A number of our users are still on IE8. Some of them sometimes report problems when trying to send data to our servers (using the large button that says "SAVE").
IE8 displays a script error, which is: An unexpected method call or access to properties, always pointing to the same line in the KnockoutJS 2.2.0 library (debug, for now), line 450, which is as follows:
return JSON.stringify(ko.utils.unwrapObservable(data), replacer, space);
The method in my code that is in the root trace line of the stack where this happens is:
self.saveSingle = function (onSuccess, onFailure) { ko.utils.arrayForEach(self.days(), function (day) { day.close(); }); var jsonData = ko.toJSON(self); $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: applicationLocation + "/api/assignmentapi/save", data: jsonData, success: function (data) { self.status(data.Status); self._isDirty(false); ko.utils.arrayForEach(self.days(), function (day) { day.clean(); }); if (onSuccess) onSuccess(); }, error: function (data) { onFailure(); }, dataType: "json" }); };
We highlight a number of properties that our POST does not need when we convert the object to JSON using this approach: http://www.knockmeout.net/2011/04/controlling-how-object-is-converted-to.html
OurType.prototype.toJSON = function () { var copy = ko.toJS(this); delete copy.someUnneededProperty1; delete copy.someUnneededProperty2; delete copy.someUnneededProperty3; delete copy.someUnneededProperty4; return copy; }
When he fails, he does not consistently work on the line
var jsonData = ko.toJSON(self);
Now here is the real mess:
- This does not always happen.
- This does not happen with all IE8 users.
- We cannot play it sequentially
- The structure of our model, which we serialize, does not look material.
- jscript.dll is the current version for IE8