Blog
Simple Search Concept using Ajax and php
Source Code:
Databse and Table:
index.php
<head>
<style type=”text/css”>
body {
margin: 0px;
}
.head {
margin-top: 0px;
background-color: #DDB744;
height: 70px;
}
.center {
width: 800px;
margin-top: 50px;
margin-left: auto;
margin-right: auto;
border: 1px solid;
padding: 55px;
border-color: #CCC;
border-radius: 12px;
height: auto;
letter-spacing: 1px;
font-size: 19px;
}
.lab {
height: 38px;
width: 450px;
margin-left: 45px;
}
.search {
height: 38px;
width: 100px;
background-color: #DDB744;
}
.foot {
margin-top: 400px;
background-color: #DDB744;
height: 70px;
}
</style>
</head>
<body>
<script language=”javascript” type=”text/javascript”>
function ajaxFunction() {
var ajaxRequest;
try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e) {
try {
ajaxRequest = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e) {
alert(“Your browser broke!”);
return false;
}
}
}
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState == 4) {
var ajaxDisplay = document.getElementById(‘ajaxDiv’);
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var EmpName = document.getElementById(‘EmpName’).value;
var queryString = “?EmpName=” + EmpName;
ajaxRequest.open(“GET”, “ajax.php” +
queryString, true);
ajaxRequest.send(null);
}
</script>
<div class=”head”>
<center>
<h1>http://www.sanwebcorner.com/</h1>
</center>
</div>
<div class=”center”>
<form name=’myForm’>
Name:
<input type=’text’ id=’EmpName’ class=”lab” />
<input type=’button’ class=”search” onclick=’ajaxFunction()’ value=’Search’ />
</form>
<div id=’ajaxDiv’> Your Result Display Here</div>
</div>
<div class=”foot”>
<center>
<h3><br>http://www.sanwebcorner.com/</h3>
</center>
</div>
</body>
</html>