AJAX can be used for interactive communication with an PHP file.
var str = "John";
//str is varable value from the Html input can be any:
function showData(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", "ajax_getdata.php?q=" + str);
xmlhttp.send();
}
}