<script type="text/javascript">
function ajaxCall(formID, showID) {
var form = $('#' + formID);
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize(),
dataType: "JSON",
cache: false,
success: function (data, status, xhr) {
$('#' + showID).html('').fadeOut('fast');
$('#' + showID).html(data).fadeIn('slow');
},
error: function (xhr, status, error) {
//alert(xhr);
console.error(xhr);
}
});
}
</script>
<p>Start typing a name in the input field below:</p>
<p>Suggestions: <span id="txtHint"></span></p>
<form>
First name: <input type="text" onkeyup="showHint(this.value)">
</form>
<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", "gethint.php?q=" + str);
xmlhttp.send();
}
}
</script>