ItSolutionStuff.com

How to Download File using JQuery?

By Hardik Savani • November 16, 2022
jQuery

Hi Friends,

In this tute, we will discuss how to download file in jquery. This post will give you a simple example of jquery download file from url. I explained simply about jquery download file response. I explained simply about jquery download csv file. So, let us dive into the details.

I will give you a very simple and short example of how to download file in jquery. we will use window.location.href to download response. so, let's run the below html file.

Example:

index.html

<!DOCTYPE html>

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

</head>

<body>

<h1>How to Download File using JQuery? - ItSolutionStuff.com</h1>

<a id="download" href="#">Click Here!</a>

</body>

<script type="text/javascript">

$(document).ready(function () {

$("#download").click(function (e) {

e.preventDefault();

window.location.href = "/docs/demo.csv";

});

});

</script>

</html>

Output:

I hope it can help you...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Count Number of Rows in Table JQuery?

Read Now →

JQuery Remove Multiple Values from Array Example

Read Now →

How to Remove Element from Array in JQuery?

Read Now →

JQuery Disable Submit Button on Click to Prevent Multiple Form Submits

Read Now →

JQuery Get Days Difference Between Two Dates Example

Read Now →

How to Get the Current URL using JQuery?

Read Now →

How to Remove Query String from URL using JQuery?

Read Now →

Check and Uncheck All Checkbox using JQuery Example

Read Now →

How to Allow Only One Checkbox Checked at a Time in JQuery?

Read Now →

How to Convert Line Breaks to br in jQuery ?

Read Now →

How to Check Object is Empty or Not in JQuery?

Read Now →