I'm using MVVM and an Observable (called _alertModel) for a jQuery AJAX post.
Passing the Observable without calling toJSON does not work.
If I use toJSON, primitives work fine but objects (Date and Array objects in particular) raise exceptions.
I've been working around these issues by copying object properties to temporary vars, replacing them with string representations for the AJAX call, restoring the objects after the call is initialized, i.e.
This seems clumsy and I'm wondering if there is a better way.
$.ajax({
url: 'REST/Alert',
type: 'POST',
data: _alertModel.toJSON(),
timeout: 5000,
dataType: 'json',
Passing the Observable without calling toJSON does not work.
If I use toJSON, primitives work fine but objects (Date and Array objects in particular) raise exceptions.
I've been working around these issues by copying object properties to temporary vars, replacing them with string representations for the AJAX call, restoring the objects after the call is initialized, i.e.
var date = _alertModel.IncidentDate;
_alertModel.IncidentDate = (date.getMonth() + 1) + "/" + date.getDate() + '/' + date.getFullYear();
$.ajax(...);
_alertModel.IncidentDate = date;
This seems clumsy and I'm wondering if there is a better way.