I have an Ajax Call to an API which will return correctly (200) when the URL and the parameters are fine. Now I am trying to force an error with a bad request. Console will inform me about error code 400 but never seems to get into the error method. Instead it gets stuck in some jquery line and never returns.
fetch: function(successCallback, errorCallback) {
var apiUrl = this.applyFilter(filters);
var self = this;
this.log('fetch', apiUrl, currentSearchMode);
$.ajax({
url: apiUrl,
type: 'GET',
cache: (debug) ? true: false,
processData: true,
crossDomain: true,
scriptCharset: 'UTF-8',
jsonp: 'callback',
dataType: 'jsonp',
success: function(data, statusText, jqXHR) {
console.log(jqXHR);
// if(jqXHR.status == 400){
// console.log('there is an error');
// }
self.log('fetch::success', data);
if (typeof data.error !== 'undefined') {
showNoResultError = true;
var appData = lastValidResult[currentSearchMode];
} else {
showNoResultError = false;
var appData = self.normalize[currentSearchMode](self, data);
lastValidResult[currentSearchMode] = appData;
}
if (typeof successCallback === 'function')
successCallback(appData);
},
error: function(jqXHR, textStatus, errorThrown) {
//do sth here
// if(jqXHR.status&&jqXHR.status==400){
// alert(jqXHR.responseText);
// }else{
// alert("Something went wrong");
// }
// console.log('works now');
// self.log('fetch::error', textStatus, errorThrown);
// if (typeof errorCallback === 'function')
// errorCallback.apply(this, arguments);
},
complete: function(jqXHR, textStatus) {
console.log(jqXHR);
console.log('complete');
}
});
},
So the image shows where it gets stuck. I can only catch complete and success functions but when there a 400 response there is nothing happening. Tried anything, also done(), fail() since I assumed there might be a problem with deprecated behavior. But same problem there. Can anybody help, please?