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):

function loadXMLDoc() 
	var str = document.forms["Form1"]["textBar1"].value;
	if (str.length == 0) 
		document.getElementById("txtHint").innerHTML = "";
	if (window.XMLHttpRequest) 
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	{// 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);
		<b>type a name below:</b>
	<form name="Form1">
		<input type="text" name="textBar1">
		<button type="button" onclick="loadXMLDoc()">Submit</button>
	<div id="textHint"></div>
		Your Typed Text : <span id="txtHint"></span>


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

// retreive and print variable
echo $_GET['p'];

You may also like...