Cześć,
Za pomocą przesłania wartości inputem przez formularz potrzebuję odwołać się ajaxem do xml i odczytać dane. Mam oto poniższy kod, ale zbyt bardzo nie chce mi to działać. Wiem, że linijka if (this.readyState == 4 && this.status == 200) nie jest wykonywany, ale mógłby ktoś mi wytłumaczyć dlaczego? I jak to naprawić, abym mógł się odwołać do xml. Dodam, że zdarzanie onclilck działa bez problemów.
<!DOCTYPE html>
<html>
<head>
<title>Test.</title>
<meta charset="utf-8">
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
table {
margin-top: 60px;
}
th,td {
padding: 5px;
}
img {
height: 100px;
width: 100px;
}
form {
margin-top: 10px;
}
</style>
</head>
<body>
<form name="theform" onsubmit="show()">
Enter name club: <input name="name" type="text" id="name">
<input type="submit" value="Show value">
</form>
<table id="demo"></table>
<script>
function show()
{
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
functionForm(this);
// ...
}
};
xhttp.open("GET", "footballers.xml", true);
xhttp.send();
function functionForm(xml) {
let xmlDoc = xml.responseXML;
let x = xmlDoc.getElementsByTagName("club");
let temp = document.querySelector("#name");
}
}
</script>
</body>
</html>