久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 POST 數據通過 jQuery AJAX 下載 PHP 文件

PHP File Download using POST data via jQuery AJAX(使用 POST 數據通過 jQuery AJAX 下載 PHP 文件)
本文介紹了使用 POST 數據通過 jQuery AJAX 下載 PHP 文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

所以我知道有很多類似的帖子,但我認為這足以證明自己的問題:

So I know there have been a number of similar posts, but I think this is enough of a variation to warrant its own question:

我正在用 PHP 和 jQuery 構建一個 XLS 導出器.我正在嘗試使用 jQuery POST 一個數組(我認為它作為 GET 查詢字符串會太長),并使用它在我的服務器上生成一個 XLS 文件,然后用戶可以下載該文件.

I am building an XLS exporter in PHP and jQuery. I am trying to POST an array with jQuery (which I believe is going to be too long as a GET querystring), and use it to generate an XLS file on my server, which the user can then download.

我過去曾使用隱藏的 iframe 來完成此操作,但由于它們只是重定向到一個 url,這需要我使用 GET,這讓我很緊張.

I have used hidden iframes in the past to accomplish this, but since they just redirect to a url, this requires me to use GET, which makes me nervous.

我的問題是:如果這些文件是由多個用戶動態生成的,我該如何將這些文件存儲在我的服務器上并鏈接到它們?隱藏的 iframe 會鏈接到一個單獨的 PHP 腳本,該腳本根據會話 ID 或類似的東西定位他們的文件嗎?

My question is then: how do I store those files on my server and link to them if they're being generated dynamically, potentially by multiple users? Would a hidden iframe link to a separate PHP script that locates THEIR file based on a session ID or something like that?

在此先感謝您對我肯定會一直被問到的問題的任何指導:)

Thanks in advance for any guidance here on what I'm sure gets asked all the time :)

推薦答案

可以 POST 到隱藏的 iframe.因此,您無需擔心查詢字符串的長度;您將發布鍵/值對,這將生成您的 XLS 文件,然后強制將文件下載到瀏覽器.

It is possible to POST to a hidden iframe. Therefore, you don't need to worry about the length of the query string; you will post the key/value pairs which will generate your XLS file and subsequently force the file download to the browser.

<form method="post" action="/download/xls" target="download_xls"> 
  <fieldset>
    <label>Key 1:</label>
    <input type="text" name="key_1" />
  </fieldset>

  <fieldset>
    <label>Key 2:</label>
    <input type="text" name="key_2" />
  </fieldset>

    <fieldset>
            <input type="submit" value="Submit" /> 
    </fieldset> 
</form>

<iframe id="download_xls" name="download_xls" width="0" height="0" scrolling="no" frameborder="0"></iframe>

更新快速谷歌搜索出現了這篇文章:http://particletree.com/notebook/ajax-file-download-or-not/

UPDATE A quick Google search turned up this article: http://particletree.com/notebook/ajax-file-download-or-not/

基本上,建議是將您的表單發布到當前頁面并通過文件下載進行響應.這種替代方案可能對您來說已經足夠了.

Basically, the suggestion is to POST your form to the current page and respond with a file download. This alternative might be good enough for you.

這篇關于使用 POST 數據通過 jQuery AJAX 下載 PHP 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 亚洲精品一二区 | 五月婷婷 六月丁香 | 黄色精品 | 五月天婷婷综合 | 久久久亚洲一区 | 久久亚洲一区二区 | 色资源站 | 国产在线一区观看 | av资源中文在线天堂 | 一级黄色片网址 | 青青草在线视频免费观看 | 国产激情综合五月久久 | www.日日操 | 国产不卡一区 | 日韩欧美二区 | 成人亚洲性情网站www在线观看 | 欧美一级做性受免费大片免费 | 久久久久一区二区三区 | 亚洲一区二区三区桃乃木香奈 | 亚洲第一网站 | 久久久久久国模大尺度人体 | 亚洲欧美日本在线 | 精品少妇一区二区三区日产乱码 | www性色 | 日本色综合 | 国产一区二区视频在线 | 国产精品视频中文字幕 | 日操夜操 | 91成人精品 | 国产精品特级片 | 天堂久久网 | 国产精品久久av | 日韩视频在线播放 | 亚洲精品久久久久久久久久久久久 | 国产一区不卡 | 91高清视频在线观看 | 伊人久久在线观看 | 亚洲国产日本 | 成人欧美一区二区三区1314 | 国产精品一区二区在线 | 国产精品色一区二区三区 |