I am utilizing Dojo's xhr function to send data to an ASP.NET MVC controller:
xhr.post("/MyController", {
handleAs: "json",
data: {
contentIdentifier: 'abc123',
language: 'en'
}
}).then(function (response) {
console.log('Success.');
}, function (err) {
console.error(err);
});
The controller is returning a response in plain text, and the server confirms with a status of 200 OK.
Despite receiving a successful response, the error handler always activates.
Upon logging the err object to the console, I observe something like this:
SyntaxError: Unexpected token S
message: "Unexpected token S"
response: {
options: TMP
status: 200
text: "Successfully pushed content to 1 instance(s)."
It appears that the issue lies in parsing plain text as JSON, causing it to break at the first letter "S" in "Successfully". Could this be what's causing xhr to throw an error?
The response header specifies a content type of text/plain