Java Reference
In-Depth Information
Once all preparation is made, you fi nally make the request for the someTextFile.txt fi le, and you
pass the options object to the Ajax.Request() constructor (don't forget the new keyword!!).
If you need to send parameters with your request, you'll have to do a bit more preparation before call-
ing new Ajax.Request(). Like jQuery, you can create an object whose property names match those of
the parameter names. For example, if your URL requires you to pass two parameters named name and
state, you can do something like the following code:
var parms = new Object();
parms.name = “Jeremy”;
parms.state = “Texas”;
options.parameters = parms;
By adding parameters and then calling new Ajax.Request(), the parameters are added to the URL
before the request is sent to the server.
Now that you've been given a crash course in Prototype's Ajax function, alter the form validator script
from Chapter 14 to use Prototype instead of the HttpRequest module.
Try It Out Revisiting the Form Validator with Prototype
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 6 with jQuery</title>
<style type=”text/css”>
.fieldname
{
text-align: right;
}
.submit
{
text-align: right;
}
</style>
<script type=”text/javascript” src=”prototype-1.6.0.3.js”></script>
<script type=”text/javascript”>
function checkUsername()
{
var userValue = $F(“username”);
if (userValue == “”)
{
alert(“Please enter a user name to check!”);
return;
}
var parms = new Object();
Search WWH ::




Custom Search