document.observe("dom:loaded", function() {
$("lookup").observe("click", doLookup);
doLookup();
});
function doLookup() {
new Ajax.Request("../urban.php",
{
method: "get",
onSuccess: gotResult,
onFailure: ajaxFailure,
onException: ajaxFailure,
parameters: {
"term": $("term").value
}
}
);
}
function gotResult(ajax) {
$("result").innerHTML = ajax.responseText;
}
// provided Ajax failure code (displays a useful alert when something goes
// wrong with the Ajax request)
function ajaxFailure(ajax, exception) {
alert("Error making Ajax request:" +
"\n\nServer status:\n" + ajax.status + " " + ajax.statusText +
"\n\nServer response text:\n" + ajax.responseText);
if (exception) {
throw exception;
}
}