On my index.html, there are buttons displayed below:
<button value="about_us.php" onClick="fNt(value)">About Us</button>
<button value="faq.php" onClick="fNt(value)">FAQ</button>
<button value="contact_us.php" onClick="fNt(value)">Contact Us</button>
I want to use AJAX to fetch information from PHP pages based on the button clicked. Instead of creating separate AJAX functions for each page, I am looking for a more efficient solution to handle multiple buttons without consuming too much space.
Is it possible to achieve something like the following?
<script>
function fNt(value) {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", value, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 {
document.getElementById("ajax").innerHTML = xmlhttp.responseText;}}}
</script>
I understand that the script above is not functional, but it illustrates what I'm trying to accomplish. Any suggestions on how to make this work? Your help would be greatly appreciated.