I have a text file and want to download it. I am working in localhost. The HTML page from which I am downloading file, is called from localhost:8080. And the file which I want to download, I am calling using another port i.e. 'localhost:100'.
If I do like this I am not getting that particular txt file, in fact the whole location of the of the folder is getting downloaded in HTML format. How to resolve this issue ?
But when the port is same for both HTML and the download URL , that particular text file is getting downloaded.
EDIT
HTML Page (http://localhost:8080/project/test.html)
<HTML>
<HEAD>
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
var url="http://localhost:100/test";
var file = "test112.zip";
saveFile(url,file); // Text Document
alert("File is downloaded");
function saveFile(fileURL,fileName){
if (!window.ActiveXObject) {
var save = document.createElement('a');
save.href = fileURL;
save.target = '_blank';
save.download = fileName || fileURL;
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0,
false, false, false, false, 0, null);
save.dispatchEvent(evt);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
}
}
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
When this runs following file gets downloaded -
download.html
In download.html there is
Index of /test
The localhost:8080 is Jetty Server and localhost:100 is Apache Server