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

155
Views
Cambiando de XMLHttpRequest() a Fetch() y aún obteniendo salida booleana

Sé que hay miles de formas de hacer esto...

Así que tengo esta función que me devuelve booleano sobre el estado de verificación del archivo HEAD usando XMLHttpRequest.

 const urlToFile = "shorturl.at/devIK"; function doesFileExist(urlToFile) { let xhr = new XMLHttpRequest(); xhr.open('HEAD', urlToFile, false); xhr.send(); return xhr.status == "404" ? false : true; }

Sin embargo, en desuso.

Ahora trato de construir y comprender cómo manejar la salida de datos de la API de recuperación. Resulta que no puedo obtener el resultado deseado.

 const urlToFile = "shorturl.at/devIK"; function doesFileExist(urlToFile) { return fetch(urlToFile, { method: 'HEAD' }) .then(res => { res.ok ? true : false; }) .then(fileExistResult => fileExistResult.boolValue()) .catch(err => console.log('Error: ', err)); }

-->

 doesFileExist(urlToFile) == true ? do_this : do_that;

Sigo sin definir desde console.log. Si pudieras ayudarme con esto... ¡Gracias de antemano!

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!