Ajax with php

With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required (JSON is often used instead), and the requests do not need to be asynchronous.

you Need two file :

1) abc.php (contains HTML/Java Script/Ajax code):

<html>
<head>
<script>
function loadXMLDoc() 
{
	var str = document.forms["Form1"]["textBar1"].value;
	if (str.length == 0) 
	{
		document.getElementById("txtHint").innerHTML = "";
		return;
	}
	if (window.XMLHttpRequest) 
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} 
	else 
	{// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET", "newfile1.php?p=" + str, true);
	xmlhttp.send();
}
</script>
</head>
<body>
	<p>
		<b>type a name below:</b>
	</p>
	<form name="Form1">
		<input type="text" name="textBar1">
		<button type="button" onclick="loadXMLDoc()">Submit</button>
	</form>
	<div id="textHint"></div>
	<p>
		Your Typed Text : <span id="txtHint"></span>
	</p>

</body>
</html>

2) Second File newfile1.php (retrieves request and return it to the calling page.)

<?php 
// retreive and print variable
echo $_GET['p'];
?>