I want to load different XML files on buttons click. How can I send it to the function?
<button onclick = 'loadXMLDoc(a.xml)'></button>
<button onclick = 'loadXMLDoc(b.xml)'><button>
<script>
function loadXMLDoc(a) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", "a", true);
xmlhttp.send();
}
</script>
Your javascript calling needs to pass a string, also the second <button>
is not closed, have a look at:
<button onclick = "loadXMLDoc('a.xml')"></button>
<button onclick = "loadXMLDoc('b.xml')"></button>
<script>
function loadXMLDoc(a) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
}
xmlhttp.open("GET", a, true);
xmlhttp.send();
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.