Javascript Ajax Call File Download
Posted : adminOn 11/24/2017Handle file download from ajax post. I see youve already found out a solution, however I just wanted to add some information which may help someone trying to achieve the same thing with big POST requests. I had the same issue a couple of weeks ago, indeed it isnt possible to achieve a clean download through AJAX, the Filament Group created a j. Query plugin which works exactly how youve already found out, it is called j. Query File Download however there is a downside to this technique. If youre sending big requests through AJAX say files 1. JavaScript d v s k r p t, often abbreviated as JS, is a highlevel, dynamic, weakly typed, prototypebased, multiparadigm, and interpreted. MB it will negatively impact responsiveness. In slow Internet connections youll have to wait a lot until the request is sent and also wait for the file to download. It isnt like an instant click popup download start. Its more like click wait until data is sent wait for response download start which makes it appear the file double its size because youll have to wait for the request to be sent through AJAX and get it back as a downloadable file. Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, and XML. Jquery. fileDownload. Library jQuery File Download is a cross server platform compatible jQuery plugin that allows for an Ajaxlike file download experience. Selfcontained crossbrowser HTML5, legacy, AJAX, drag drop JavaScript file upload. Dependenciesfree. Sce Refrigerator Program. With jQuery plugin. If youre working with small file sizes lt 1. MB you wont notice this. But as I discovered in my own app, for bigger file sizes it is almost unbearable. A set of keyvalue pairs that configure the Ajax request. All settings are optional. A default can be set for any option with. Setup. See jQuery. Ajax also AJAX e d k s short for Asynchronous JavaScript And XML is a set of Web development techniques using many Web technologies on the client. Description Load JSONencoded data from the server using a GET HTTP request. Query. getJSON url, data, success. I have an action class that generates a pdf. The contentType is set appropriately. MyAction extends ActionSupport public String execute. My app allow users to export images dynamically generated, these images are sent through POST requests in base. MB are huge, this force users to wait more than necessary for the file to start downloading. In slow Internet connections it can be really annoying. My solution for this was to temporary write the file to the server, once it is ready, dynamically generate a link to the file in form of a button which changes between Please wait. Download states and at the same time, print the base. This makes all the waiting time more bearable for users, and also speed things up. Update Sep 3. 0, 2. Months have passed since I posted this, finally Ive found a better approach to speed things up when working with big base. I now store base. I pass its record ID through the j. Query File Download, finally on the download script file I query the database using this ID to pull the base. Download Script Example lt ID intPOSTid. Query Data this example uses Code. Igniter. data CI My. Queries Get. Download download. ID. base. 64 tags are replaced by removed, so we strip them out. This example is for base. Set content headers. Content Disposition attachment filenamemy file. Content type. imgsizemime. Force download. I know this is way beyond what the OP asked, however I felt it would be good to update my answer with my findings. When I was searching for solutions to my problem, I read lots of Download from AJAX POST data threads which didnt give me the answer I was looking for, I hope this information helps someone looking to achieve something like this.