The ajax call needs a token that expires frequently. There is no external process to periodically fetch a new token so I'm stuck. What I'd like to happen in this scenario when it's expired is: 1.Function fails 2.Fail case executes a new call to get a new token 3. Original Ajax call tries again, this time with a good token. Below is what I have:
$.ajax({
method: "GET",
url: myUrl,
headers: { "Authorization": "Bearer " myToken}
})
.done(function(data, statusText, xhr){
//All good here
})
.fail(function (xhr, response){
if(xhr.status == 401){
//Here is where I'm looking to find a solution
//First get new token here ex. function getToken()
//Next retry above function
}
});