Using Prototype
In this sample, when you click "Get Time", the script runs time.php which just prints the date and time, which is returned in the division with ID "box". The second function showURL runs parse.php which will output html to the division.
<script type="text/javascript" src="ssi/prototype-1.5.1.1.js"></script>
<script type="text/javascript">
var random_variable = "rv=" + parseInt(Math.random()*99999999999);
function getTime(){
new Ajax.Request('time.php?' + random_variable,
{
method:'post',
onSuccess: function(transport){
var response = transport.responseText || "no response text";
alert("Success! " + response);
},
onFailure: function(){
alert('Something went wrong...');
}
}
);
}
function showURL(some_id,action){
new Ajax.Request('parse.php?action=' + action + '&' + random_variable,
{
method:'post',
onSuccess: function(transport){
var response = transport.responseText || "no response text";
document.getElementById(some_id).innerHTML = response;
},
onFailure: function(){
alert('Something went wrong...');
}
}
);
}
</script>
<p><a onclick="showURL('box','open_dir')" href="#">Show Directories</a>
<a onclick="showURL('box','show_pictures_1')" href="#">Show Pictures</a>
<a onclick="showURL('box','show_pictures_2')" href="#">Show Pictures 2</a></p>
<div id="box">
</div><!--box-->
[Click to add or edit comments])
Please prepend comments below including a date