I am posting some JSON data to my action method like so:
$.ajax({
url: this.options.url,
type: 'POST',
dataType: 'json',
data: values,
success: function (html, status, response) {
// do whatever
},
error: function (error) {
// do whatever
}
})
I am succesfully hitting the server, with the correct values present, no errors are being thrown but yet the error event is hit up completion, not the success event. On inspecting the response object in the error event I can see that I am getting a 200 ‘OK’ back. I can also see that response text is what I would expect it to be.
I assume this is because I am posting JSON but returning text? Is it possible to have a different dataType for each direction?
The
dataTypeproperty is used to signify the type of data you’re expecting in response to the call, not the type of data you’re sending, so your call is expecting a JSON response, but is getting plain text instead.