Gaspare Sganga

IT Manager, GIS Analyst & Lead Developer @setin.

Freelance Developer & Consultant.

Buy me a coffee?


Quick Demo

Get it


View project on GitHub or download the latest release.


npm install gasparesganga-jquery-ajax-downloader


bower install gasparesganga-jquery-ajax-downloader


CDN hosting of this library is possible thanks to jsDelivr. For more details about URL structure please refer to the official documentation.
On the CDN configuration page you can find all the available files and versions of this library, select a specific version, use range or latest version aliasing, join more files in a single request and enable subresource integrity (SRI).

How it works

An HTML form is created and submitted to ad invisible IFrame. You can pass parameters like you would in a regular Ajax request.
The server should answer the request providing a file to download of course.


The only method provided works like any other Ajax call made with jQuery, thus using the defaults provided with $.ajaxSetup().


Performs an ajax-style download

Options and defaults values

data   : $.ajaxSetup()["data"]    // Object
url    : $.ajaxSetup()["url"]     // String

Data to send to the server along the request (it acts the same way as jQuery.ajax() data parameter).


URL to which the request is sent (it can be a static file to download as well).


A couple of examples using both a static file and a dynamic request:

Example 1 - Static File

    url  : "./"

Example 2 - Dynamic Request

    url  : "./download_manager.php",
    data : {
        param1   : "xxx",
        param2   : "yyy",
        param3   : "zzz"

Server Side

Some care should be taken server side too. In my first example I requested a static file and it seemed to work just fine. But what would have happened with a PDF file or any other file format that your browser can actually open?
The solution is easy, just do some server side magic, like sending the right headers. Here is a PHP example to serve a static file forcing a download dialog on the user’s browser:

        Do some parameters checks, database data collection, etc. etc. here
    // Force a download dialog on the user's browser:
    $filepath = '/path/to/file.pdf';
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
    header('Content-Transfer-Encoding: binary');
    header('Cache-Control: must-revalidate');
    header('Content-Length: '.filesize($filepath));


12 November 2016 - Version 1.1.0
4 May 2015 - Version 1.0

Comments and Ideas

Want to leave a comment or give me an idea? Send me an or use the comments section below.