Professional Documents
Culture Documents
How AJAX Works
How AJAX Works
-> AJAX stands for Asynchronous JavaScript and XML. AJAX is a technique for
creating fast and dynamic web pages.
<html>
<head>
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML =
xmlhttp.responseText;
}
}
xmlhttp.open("GET", "gethint.php?q=" + str, true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<?php
// Array with names
$a[] = "Abhi";
$a[] = "Bobby";
$a[] = "siri";
$a[] = "keerthi";
$a[] = "sailu";
$a[] = "akki";
$hint = "";
<html>
<head>
<script>
function showUser(str)
{
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Abhinav</option>
<option value="2">Alekhya</option>
<option value="3">Siri</option>
<option value="4">Sailu</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
</body>
</html>
--------------------------------------------------------------------
<!—source code for getuser.php -->
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','','nit');