I am using a jsonp ajax request with jQuery to send some data. When this data could not be processed for some reason, I would like to return the result with a http status other than 200. This way I can use my access logs to parse them for statistics.
Unfortunately, I don't get any response when the status code is not 200, although the jQuery callback is in the response body (when I check with firebug). Is there a way to catch the response?
$.ajax({
type: 'GET',
url: '{{ sendMsgUrl }}',
async: false,
data: { 'form': formData },
dataType: 'jsonp',
success: function(json2) {
if (json2.status == 'ok')
// do stuff
else {
// output error
};
},
error: function(xhr, status, error) {
// this doesn't work: it never gets here
alert(xhr.responseText);
var json2 = eval("("+xhr.responseText+")");
}
}).fail(function(jqXhr) {
// never gets here either
alert('status '+jqXhr.responseJSON);
});