Good evening, I am a beginner, I am on an application where the client has to download one of the xml files, but when the file is in local folder it downloads it and when it is elsewhere, it says:
GET https://localhost/dossier/data.xml 404 (Not Found)
.
How to make it accept the file no matter where it is?
This is the code:
<form id="parcourir">
<input type="file" id="real-file" hidden="hidden" />
<button type="button" id="custom-button">Parcourir</button> <br>
<span id="custom-text">Aucun fichier selectionné</span>
</form>
<script>
const realFileBtn = document.getElementById("real-file");
const customBtn = document.getElementById("custom-button");
const customTxt = document.getElementById("custom-text");
customBtn.addEventListener("click", function () {
realFileBtn.click();
})
realFileBtn.addEventListener("change", function () {
if (realFileBtn.value) {
customTxt.innerHTML = realFileBtn.value.match(/[\/\\]([\w\d\s\.\-\(\)]+)$/)[1];
console.log(location.href);
console.log(customTxt.innerHTML);
myFunction(this);
} else {
customTxt.innerHTML = "no file choosen yet";
}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", customTxt.innerHTML, true);
xhttp.onload = (response) => {
console.log(xhttp.response);
}
xhttp.send();
})
function myFunction(xml) {
var xmlDoc = xml.responseXML;
console.log(xmlDoc);
}
</script>