Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Can an Ajax call get a token and retry itself after a 401

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


        }
    });
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!