Example #1
Request the test.php page and display the response in a div with the id "test1".
function test1() {
Ajax.get({
'url' : 'test.php',
'element' : 'test1'
});
}
Run Test One
Example #2
Request the test.php page with the value from the "name" input box and display the response in a div with the id "test2".
function test2() {
var nam = document.getElementById("name").value;
Ajax.post({
'url' : 'test.php',
'element' : 'test2',
'parameters' : { 'name' : nam }
});
}Example #3
Request the test.php page with the value from the "color" input box and display the response in an input element with the id "test3".
function test3(colr) {
Ajax.pause({
'url' : 'test.php',
'element' : 'test3',
'outputtype' : 'input',
'parameters' : { 'color' : colr }
});
}This will run when you stop typing... Unless you type really slow, then it might run a few times.
Example #4
Request the test.php page, display a spinner and a message for 2 seconds, then display the response.
function test4() {
Ajax.pause({
'url' : 'test.php',
'element' : 'test4',
'parameters' : { 'varA' : 'foo', 'varB' : 'bar' },
'pause' : 2000,
'spinner' : '/images/spinner.gif, please wait 2 seconds.'
});
}
Run Test Four
Example #5
Request the test.php page and run a function that displays the response in an alert box.
function test5() {
Ajax.get({
'url' : 'test.php',
'onSuccess' : function(req) { alert(req.responseText); }
});
}
Run Test Five
Example #6
Request the testerror.html page which doesn't exist and display the error in an alert box.
function test6() {
Ajax.get({
'url' : 'testerror.html',
'onError' : function(req) { alert(req.errorText); }
});
}
Run Test Six
Documentation Download
