Javascript AJAX Database Example

AJAX can be used for interactive communication with a database.

Example – The showCustomer() Function

When a user selects a customer in the dropdown list , a function called showCustomer() is executed. The function is triggered by the onchange event:

showCustomer

function showCustomer(str) {
  if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
    return;
  }
  const xhttp = new XMLHttpRequest();
  xhttp.onload = function() {
    document.getElementById("txtHint").innerHTML = this.responseText;
  }
  xhttp.open("GET", "getcustomer.php?q="+str);
  xhttp.send();
}

The showCustomer() function does the following: Continue reading Javascript AJAX Database Example