Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
630 B
1
Indexable
Never
<html>
<body>
<h1>AJAX avec PHP</h1>
<h3>Saisir le nom d’un pays</h3>
Pays: <input type="text" id="txt1" onkeyup="Suggestions(this.value)">
<p>Suggestions: <div id="div1"></div></p> 
<script>
function Suggestions(str) {
  var xhttp;
  if (str.length == 0) { 
    document.getElementById("div1").innerHTML = "";
    return;
  }
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("div1").innerHTML =this.responseText ;
    }
  };
  xhttp.open("GET", "page4.php?q="+str, true);
  xhttp.send();   
}
</script>
</body>
</html>