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;

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.