I just recently started using AJAX myself for a project of mine. It was a bit confusing, especially considering how many different ways to implement it there are. Here is the basic function I am using to apply ajax.
Code:
function handle_stuff(m_varA, m_varB) {
$.post("handle_stuff.php", {
varA: m_varA,
varB: m_varB
}, function (data) {
if (data.length > 0) {
$(".div_class").html(data)
}
})
}
Here's essentially what this does...
First, the javascript function handle_stuff needs to be called. I do this through an onClick with a link, but you can also do it in many other situations.
The javascript function is called with two parameters. varA and varB.
Next, varA and varB are sent to handle_stuff.php as post variables. Thus, I can access them through handle_stuff.php with
$_POST['varA'] or
$_POST['varB'].
Then, the div with the class
div_class is modified to display the
data variable, which should be a string.
The
data variable is filled with whatever is echo'd out by handle_stuff.php.
So, if I put at the end of handle_stuff.php:
then the data variable in the handle_stuff javascript function will be
RaGEZONE.
For me, I use a function very similar to this, so that when a user hits a plus or minus button, then a score is automatically updated and displayed on the same page - all without having to refresh the full page.
I hope this helped a bit. Once again, best of luck.
P.S. I am pretty sure the function I gave you requires jQuery.