How to Download File using 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Count Number of Rows in Table JQuery?
- JQuery Remove Multiple Values from Array Example
- How to Remove Element from Array in JQuery?
- JQuery Disable Submit Button on Click to Prevent Multiple Form Submits
- JQuery Get Days Difference Between Two Dates Example
- How to Get the Current URL using JQuery?
- How to Remove Query String from URL using JQuery?
- Check and Uncheck All Checkbox using JQuery Example
- How to Allow Only One Checkbox Checked at a Time in JQuery?
- How to Convert Line Breaks to br in jQuery ?
- How to Check Object is Empty or Not in JQuery?