I'm facing an issue where I need to call the method getData() inside my AJAX function again if a 401 status occurs and the counter is less than or equal to 1. However, for some reason, the method is not being called in that particular scenario. How can I go about calling that method from within the same class?
export default class Search {
constructor(){
this.result = {};
}
getData(callback, url){
var counter = 0;
alert("GET DATA CALLED " + counter);
$.ajax({
'url': proxy + url,
'type': 'GET',
'content-Type': 'x-www-form-urlencoded',
'dataType': 'json',
'headers': {
'Authorization': 'bearer ' + localStorage.access_token
},
'success': function (result) {
documentView.fillDocuments(result);
callback(result);
},
'error': function (XMLHttpRequest, textStatus, errorThrown) {
// alert('Error: ' + errorThrown);
console.log(XMLHttpRequest.status + ' ' +
XMLHttpRequest.statusText);
return "";
}, statusCode: {
401: function (response) {
counter++;
alert("401");
if(counter <= 1){
refreshToken(); // CALLED
getData(callback, url); // NOT CALLED
}
}
}
});
}