I got started with AJAX a couple of months ago and I love it.. There are few websites out there that have good tutorials, however, I have been using the same script for awhile, maybe this will help you get a feel for AJAX and say no more iframes!
There are three elements to my AJAX script
1. The main page, or page you are displaying
2. a javascript page, which is called into the main page
3. the results php page, which will display in a div on the main page right before your eyes
main page (hello_world.php)
<script language="JavaScript" src="world.js"></script>
<?php
//php code here
$variable_from_page = "just an example variable";
?>
<div id="div_world"></div>
<a href="#" onclick="world('<? echo "$variable_from_page"; ?>');">Click for AJAX</a> Javascript page (world.js)
var xmlHttp
function world(variable_from_form)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="world.php"
//this passes the variable to world.php via get variable, you can add as many as you want
url=url+"?variable_from_form="+variable_from_form+"&"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("div_world").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
And finally the page that will display in the div (world.php)
<?php
$variable = $_GET['variable_from_form'];
//even though we have the variable from form I will output hello
//I just brought this variable along to show how to get it from the main page to the div
echo "Hello World";
//you can exicute any code here and it will output in the div where world went
?>