I have a simple contact form for download excel file . Main issue happen , When ajax load .I want to download excel file then redirect user to a next page.. Below is my code wit
In Ajax....Simply you can create an excel file on server ... ajax response will be the path of the excel file...On ajax success open the excel file in new tab (it automatically downloads excel) and at the same time open new tab with new location.
sample code inside ajax success given below
window.open("path to excel..");
window.open("new location");
also can use (if needed)
window.location.replace("new location");
Open multiple links in Chrome at once as new tabs
I think it is very tough to download. Please Use PHP Excel to Create file and download.
Try below method, hope it will work
ajaxexcel.php
in new window via window.open
You can't download file using Ajax request. Any how you have to redirect to particular location which will allow you to download file. Might be you tried with this, but try to download file in separate tab and redirect your page to particular page.
<input id="btnGetResponse" type="button" value="Redirect" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btnGetResponse").click(function () {
window.open('/test/excel.php');
window.location = "http://stackoverflow.com/";
});
});
</script>
Also from your PHP file (excel.php) remove this line. Otherwise it will download your file as JPG or PNG
header('Content-type: image/jpeg,image/gif,image/png');
By using https://github.com/johnculviner/jquery.fileDownload
Also from your PHP file (excel.php) remove this line. Otherwise it will download your file as JPG or PNG
header('Content-type: image/jpeg,image/gif,image/png');
Just use with simple javascript
window.location.replace(###file url###);