Download PDF File From URL Using jQuery AJAX Method

In this tutorial, you will learn how to download a PDF file from a URL using jQuery and AJAX. We will also use some HTML5 and core JavaScript code to build the application.

The complete source code of the PDF downloader developed using jQuery and AJAX is given below.

To get started, simply create a new HTML file index.html and copy/paste the below-mentioned code into it.


<button type="button" id="download_pdf_file">Download PDF File!</button>
<script src=""></script>
$('#download_pdf_file').on('click', function () {
        url: '',
        method: 'GET',
        xhrFields: {
            responseType: 'blob'
        success: function (data) {
            var a = document.createElement('a');
            var url = window.URL.createObjectURL(data);
            a.href = url;
   = 'my_file.pdf';

Code Explanation

  1. At first, we will create a button using HTML. The user will click this button to download the file.
  2. Load the jQuery using CDN.
  3. Attach an onClick event to the “Download PDF File!” button. This method will be executed whenever the button is pressed.
  4. Now make an AJAX call to the desired PDF file using the built-in ajax() method of jQuery.

Run the Project

In order to see our code in action, go ahead and open the index.html file in your favorite web browser.

The output will look something like this screenshot.

Download PDF File using jQuery AJAX

Here, you need to click the “Download PDF File!” button.

When you click this button, the PDF file will automatically start downloading on your PC.

PDF File Downloaded using jQuery and AJAX

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.