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