dongxili9934 2015-03-20 16:39
浏览 52
已采纳

Jquery帖子和php标题

I think I have a header related problem, am kinda new to them; here we go: On 'summary.php' I have links that when I click, ajax a value to another page called 'note.php'. Note.php has a header which i use to produce an MS-Word document - this works fine BUT ONLY WHEN I RUN note.php DIRECTLY, the Word file gets downloaded easily. But no Word file download when I use the click-button-to-download-document. Where should I look?

session_start();
include('otc_toolbox.php');
//ob_flush();

/*
if(isset($_POST["month"]))
{
    $month = $_POST["month"];
    $member= $_POST["member"];
}
*/

$month = $_POST["month"];
$member= $_POST["member"];

//else exit();


//Get current date
$date = date('Y-m-d');

//Prepare document html
$dnoteHTML = '';

$dnoteHTML .= '<html><body><table style="width:100%;">';

......

//header("Content-type: application/vnd.ms-word");
//header("Content-Disposition: attachment;Filename=DebitNote.doc");

echo $dnoteHTML;
  • 写回答

1条回答 默认 最新

  • dqf35839 2015-03-24 08:30
    关注

    You can't trigger a file download from an AJAX request.

    With the content disposition set to attachment, using

    window.location.href = "note.php";
    

    should trigger the download without actually navigating away from the original page.

    If the document takes a long time to generate, you could split the generation and download into two separate parts - AJAX request to a "generate" page to create the document, then when that's done, aim the browser at the "download" page to download it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo