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

152
Views
Obtener token de api e interceptar llamada ajax en jquery

Estoy tratando de obtener un token de API y quería enviar cada llamada ajax en jquery.

 function fetchToken(){ // duplicate backend call by `delay` returns a promise return new Promise(function (resolve, reject) { setTimeout(function () { resolve('test'); }, 500); }); } function interceptAjaxCall(){ var ajaxReference = $.ajax; $.ajax = function (options) { fetchToken() .then(function (tokenfrombackend) { console.log(tokenfrombackend); var success = options.success; options.headers = { 'token':tokenfrombackend}; //this does not set token in each ajax call header! options.success = function (data, textStatus, jqXHR) { if (success) success(data, textStatus, jqXHR); }; //return ajaxReference .apply($, arguments); /*returning here fails ajax call*/ }) return ajaxReference.apply($, arguments); }

La intercepción de cada ajax funciona, pero no establece el token en cada encabezado de ajax, incluso después de obtener el valor del token. Gracias por adelantado

about 4 years ago · Juan Pablo Isaza
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!