Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将pdf从python(金字塔)发送到jquery ajax_Javascript_Jquery_Ajax_Jinja2_Pyramid - Fatal编程技术网

Javascript 将pdf从python(金字塔)发送到jquery ajax

Javascript 将pdf从python(金字塔)发送到jquery ajax,javascript,jquery,ajax,jinja2,pyramid,Javascript,Jquery,Ajax,Jinja2,Pyramid,如何发送可渲染到jinja2的PDF文件?? 如果可能,编写代码(.py)和(.js)。 这是我的ajax代码 $("#print").click(function(event) { $.ajax( { type: "POST", url: "/printledgerreport", global: false, async: false, dataType : 'json', //contentType : 'application/pdf'

如何发送可渲染到jinja2的PDF文件?? 如果可能,编写代码(.py)和(.js)。 这是我的ajax代码

$("#print").click(function(event) {
$.ajax(
  {
    type: "POST",
    url: "/printledgerreport",
    global: false,
    async: false,
    dataType : 'json',
    //contentType : 'application/pdf'

    data: {"backflag":0,"accountcode":$("#accountcode").val(),"calculatefrom":$("#calculatefrom").val(), "calculateto":$("#calculateto").val(),"financialstart":sessionStorage.yyyymmddyear1,"projectcode":$("#projectcode").val(),"monthlyflag":false,"narrationflag":false},
    beforeSend: function(xhr)
    {
      xhr.setRequestHeader('gktoken',sessionStorage.gktoken );
    },
    success: function(data){
      window.open("ledgerReport.pdf");
    }
  });
});
请告诉我如何写金字塔码

下面是我的新金字塔代码:

@view_config(route_name="printledgerreport", renderer="")
def printLedgerReport(request):    
    filepath = ("ledgerReport.pdf")
    response = FileResponse(filepath)
    response.headers['Content-Disposition'] = ("attachment;             filename=ledgerReport.pdf")
    return response

试试这个。我在喝第五杯玛格丽塔酒。它应该有用。:)记住为“下载PDF”添加路径


哎呀。这只是下载文件。也许你可以和jinja合作。再一次。太多的玛格丽特:)

试试这个。我在喝第五杯玛格丽塔酒。它应该有用。:)记住为“下载PDF”添加路径


哎呀。这只是下载文件。也许你可以和jinja合作。再一次。太多的玛格丽特酒:)

这个问题需要更多的投入和澄清;以目前的格式,读者无法理解作者的问题。这是我的新代码。请检查并告诉我如何从Ajax打开pdf文件。这个问题需要更多的输入和澄清;以目前的格式,读者无法理解作者的问题。这是我的新代码。请检查并告诉我如何从ajax打开pdf文件。您是否可以编写ajax代码以打开该pdf文件?您是否可以编写ajax代码以打开该pdf文件?我的pdf文件目前尚未收到js,还有,我想把一些数据发送到python文件,然后以pdfIt的形式发送回响应听起来像是想在html中嵌入PDF文件,对吗?看看这个答案。不,我觉得pdf没有收到。你必须把你的问题说得更清楚。你能为同样的东西写ajax代码吗?我会打开那个pdf文件。你能为同样的东西写ajax代码吗?它会打开那个pdf文件吗?我的pdf文件在js没有收到,而且,我想将一些数据发送到python文件,然后以pdfIt的形式发送回响应听起来像是要在html中嵌入PDF文件,对吗?看看这个答案。不,我觉得pdf没有收到。你必须把你的问题弄清楚。
@view_config(route_name="download_PDF", renderer="")
 def download_view(request):
     filepath = ("pathtomyfile/test.pdf")
     response = FileResponse(filepath)
     response.headers['Content-Disposition'] = ("attachment; filename=test.pdf")
     return response