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

143
Views
Formulario vacío al cargar un archivo PDF con XHR

Tengo una función para obtener una entrada de tipo de archivo y cargar el archivo seleccionado usando xhr, el problema funciona bien con las imágenes, pero una vez que intento cargar un archivo pdf, la función js

 function uploadFile() { const files = document.getElementById("file").files; if(files.length > 0 ){ const formData = new FormData(); formData.append("file", files[0]); formData.append('__csrf', document.getElementById('csrf_profile').value); const xhr = new XMLHttpRequest(); // Set POST method and ajax file path xhr.open("POST", "/api/user/background", true); // call on request changes state xhr.onreadystatechange = function() { if (this.readyState === 4) { const response = JSON.parse(this.responseText); if(response.status === true){ document.getElementById('message').innerText = 'cover image has been updated'; document.getElementById('message').style.color = 'var(--main-colo)'; reloadPage(); }else{ document.getElementById('message').innerText = response.message; document.getElementById('message').style.color = '#F00'; } } }; // Send request with data xhr.send(formData); }else{ document.getElementById('message').innerText = "Please select a file"; document.getElementById('message').style.color = '#F00'; } }

en mi controlador de PHP estoy depurando usando

 die(print_r($_POST,true));

si es una imagen obtengo Array ( [__csrf] => token ) si es un pdf obtengo Array ( ) esto es lo que no pude entender, qué estoy haciendo exactamente mal aquí

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!