Some of my users are getting an error when submitting data and I see why. I checked the logs and the following 2 errors are often appearing in the logs...
- Invalid object passed in, ':' or '}' expected. (2896)
- Unterminated string passed in. (2896)
My project is an MVC web site, and the post is being made by an jQuery Ajax call, as follows:
var responses = [];
$(".item").each(function () {
var id = $(this).attr('id');
var value = $(this).val();
var response = { "ItemId": id, "Value": value };
responses.push(response);
});
$.ajax({
type: "POST",
url: myUrl,
data: JSON.stringify({ string1: string1, string2: string2, responses: responses }),
contentType: "application/json; charset=utf-8",
success: function (result) {
alert('Saved');
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Could not save, please try again later.');
}
});
There is some anecdotal evidence that the problem only happens in Chrome, but this might not be the case.
The number in the error always seems to be 2896, which I assume is the position in the string where the JSON syntax error is occurring (can't find much about the details of the error message itself - where it's being thrown or what the number means). The two error messages suggest to me that somewhere along the line (either in the JSON.stringify, the jQuery AJAX post or MVC receiving the post) the string is being truncated to 2896 chars, but I am able to post much larger strings and it works fine.
I've not been able to recreate this myself in Chrome or anywhere else, and I'm not sure what to do next.
This article is for mostly different technology, but interested me because it too suggests some kind of truncate at 2896 chars, but I'm not sure how/where that could apply to my configuration.