Java Reference
In-Depth Information
options.onFailure = request_onfailure;
options.url = “someTextFile.txt”;
var request = new Request(options).send();
The fi rst few lines of code defi ne the
request_onsuccess()
and
request_onfailure()
functions.
After the function defi nitions, you create an
options
object. The fi rst option you set is the
method
option, which you set to
get
. The next two options are the
onSuccess
and
onFailure
options, and you
assign them the
request_onsuccess()
and
request_onfailure()
functions. The fi nal option is
url
,
which you assign
someTextFile.txt
.
Once you have all the options created, you call the
Request
constructor and pass the
options
object to
it. You then chain the
send()
method, which sends the request.
You can send parameters by using the
send()
method. Simply pass it a string containing the param-
eters, as the following code shows:
var request = new Request(options).send(“name=Jeremy”);
Let's use MooTools' Ajax utilities to modify the form validator from the previous chapter one last time!
Try It Out Revisiting the Form Validator with MooTools
Open your text editor and type the following:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<title>Chapter 15: Example 8 with MooTools</title>
<style type=”text/css”>
.fieldname
{
text-align: right;
}
.submit
{
text-align: right;
}
</style>
<script src=”mootools-1.2.3-core-yc.js” type=”text/javascript”></script>
<script type=”text/javascript”>
function checkUsername()
{
var userValue = $(“username”).value;
if (userValue == “”)
{
alert(“Please enter a user name to check!”);
return;