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

292
Views
Cómo convertir Ajax (Jquery) en fetch async

Escribí este código y funciona perfecto para mí. Pero cuando intento convertirlo para buscarlo, no funciona porque devuelve una promesa. No sé cómo usarlo como asíncrono falso al buscar.

 'getProjectConstants': function(constArray) { var result=''; $.ajax({ type: "GET", url: `${constProjectBaseUrl}/ajax/getProjectConstants/${constArray}`, async: false, dataType: "json", success: function(data) { result = data } }); return result

Traté de hacer así, pero no funciona

 fetch(`${constProjectBaseUrl}/ajax/getProjectConstants/${constArray}`) .then((response) => response.json()) .then((response) => { // console.log(response) return response }) // end of .then((response) => { .catch(error => { console.log("[ajax.getProjectConstants] Error => " + error); }); // end of .catch(error => {
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes probar esto:

 async function getProjectConstants(){ const json = await (await fetch(`${constProjectBaseUrl}/ajax/getProjectConstants/${constArray}`)).json(); return json; } ajax.getProjectConstants(['PROJECT_PASSWORD_MINIMUM', 'OWNER_NAME', 'DB_TBL_TIME_ZONE']).then((constant) => { console.log(constant.OWNER_NAME) }).catch(console.error);
about 4 years ago · Juan Pablo Isaza Report
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!