Estoy creando un sistema de descarga de archivos zip en php con jquery ajax. Cuando el usuario hace clic en el botón de descarga, la solicitud va al servidor y devuelve el nombre del archivo. Puedo descargar el archivo, pero muestra el nombre del archivo completo junto con la ruta del archivo en la consola. No quiero esto.
<button onclick="checkPayment(this.id)" id="filetoDownload_1">Download File</button>JavaScript
function checkPayment(data){ $.ajax({ type: 'post', url: '../download.php', data: data, async: false, success: function(result) { let returnkd = JSON.parse(result); if(returnkd["status"]){ $("#success").html(`<div class="card"><div class="card-body bg-white text-black">Download will start soon...</div></div>`); setTimeout(() => { window.location.href = returnkd["filename"]; }, 2000); }else{ $("#error").html(`<div class="card"><div class="card-body bg-white">Something wents wrong... contact admin</div></div>`); } } }); }PHP
// wothout header if(isset($_POST)){ some code return array("status"=>true,"filename"=>"../folder/filename.zip"); } // with header if(isset($_POST)){ some code here downloadFile($filename); return array("status"=>true,"filename"=>"../folder/filename.zip"); } function downloadFile($filename) { $filename = $filename; $filepath = "../".$filename; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . $filename . '"'); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($filepath)); ob_end_flush(); @readfile($filepath); } cómo descargar un archivo sin redirigir window.location.href o mostrar la ruta del archivo en la consola. He probado el encabezado php pero no funciona.