I am creating a WordPress website that utilises a search bar. The user's search would search through an array saved in a separate file (called allcompanies.php) but I keep getting a 404 error saying the allcompanies.php can't be found.
I have used the example from here: https://www.w3schools.com/php/php_ajax_php.asp
Both header.php and allcompanies.php files are stored in the /public_html/wp-content/twentytwentyone folder so how do I reference the allcompanies.php file from the header.php (or from the functions.php) file
<input type="text" id="fname" name="fname" onkeyup="showHint(this.value)">
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
document.getElementById("txtHint").innerHTML = this.responseText;
}
xmlhttp.open("GET", "allcompanies.php?q=" + str);
xmlhttp.send();
}
}
</script>