function sendXML(xml, name) { | |
const xhttp = new XMLHttpRequest(); | |
xhttp.open("POST", "/"); | |
xhttp.onreadystatechange = () => { | |
if (xhttp.readyState == 4 && xhttp.status == 200) { | |
const res = xhttp.response; | |
alert(`${res}: ${name}`); | |
} | |
}; | |
xhttp.setRequestHeader("Content-Type", "text/xml"); | |
xhttp.send(xml); | |
} | |
function processFile() { | |
const file = document.getElementById("xml-upload").files; | |
const name = file[0].name; | |
const reader = new FileReader(); | |
let xml; | |
reader.readAsText(file[0]); | |
reader.onload = function(e) { | |
xml = e.target.result; | |
const beginXML = xml.search("<albums"); | |
xml = xml.substring(beginXML, xml.length); | |
sendXML(xml, name); | |
}; | |
} |