Javascript 当点击下载按钮时,下载应该发生在后端

Javascript 当点击下载按钮时,下载应该发生在后端,javascript,php,html,ajax,Javascript,Php,Html,Ajax,我有一个下载按钮..点击下载按钮后,下载应该在后端进行,我应该继续执行其他任务..当我点击其他按钮时,下载不应该中断..php中是否有处理此问题的方法。。如果是,可以使用什么方法 我试过使用旋度函数 <? $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://localhost:8888/test/download_ipad.php'); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true)

我有一个下载按钮..点击下载按钮后,下载应该在后端进行,我应该继续执行其他任务..当我点击其他按钮时,下载不应该中断..php中是否有处理此问题的方法。。如果是,可以使用什么方法 我试过使用旋度函数

<?
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://localhost:8888/test/download_ipad.php');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);

curl_exec($ch);
curl_close($ch);
?>


但是它不是下载而是打印整个文件

创建一个新的php文件,并在按钮href标记中提供指向该文件的链接

在php文件中,您需要为pdf和文件路径设置标题,例如:

<?php 
     $filename = "filepath";
//header for the file type
header('Content-type: audio/mp3');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Length: " . filesize($filename));
readfile($filename);

它应该下载到哪里?当您单击下载时,它必须作为xls文件下载