English 中文(简体)
从一个jax员额下载
原标题:download pdf from ajax post

我想通过一个支架哨所下载一个pdf文档。 我试图这样做:

$( #downloadPdf ).click(function() {
    var id = $( #fileId ).val();

    $.ajax({
        type: "POST",
        url: "includes/download_pdf.php",
        data:  file_id=  + id,
        complete: function(data) {
            $( #pdf_results ).html(data.responseText);
        }
    });
});

Code PHP:

<?php 
    $file_name = $_POST[ file_id ]; 
    // We ll be outputting a PDF header( Content-type: application/pdf ); 
    // It will be called downloaded.pdf header( Content-Disposition: attachment; filename=" .$file_name. .pdf" ); 
    // The PDF source is in original.pdf readfile( /var/www/vhosts/domain.nl/private/ .$file_name. .pdf ); 
?>

当我使用该守则时,我会在<代码>#pdf_results上看到所有奇怪的迹象。 我想把国防军拯救到我的电脑中,但这项工作十分艰巨。

有些人知道如何解决这一问题?

提前感谢!

问题回答

你们不需要为此利用美国航天中心。 要求使用这样的东西:

$(function(){
    $( #downloadPdf ).click(function(){
        var id = $( #fileId ).val();
        window.open(location.protocol +  //  + location.hostname +  /includes/download_pdf.php?file_id=  + id);
        return false;
    });
});

Cheers!

这里不需要麻省。

Try using Rory McCrossan s solution: POST to server, receive PDF, deliver to user w/ jQuery

要么使用原始材料,要么简单地与档案链接,确保服务器发送正确的头盔(可读到存放处的档案,然后从那里输出:

Have an invisible <iframe/> on the page, and create a <form> with attributes method="POST" action="includes/download_pdf.php" target="name_of_the_iframe", add a <input type="hidden" name="file_id" value="the_value"/> into it, and submit it.

所有这一切都可以在 Java文中完成,而不必将这种标记放在网页上,以保持清扫。 而其中没有一个是麻省。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签