Java Reference
In-Depth Information
}).get({
data: {
username: userValue
}
});
The
onSuccess
callback function varies between the different types of requests. For ordinary
Request
objects, the
onSuccess
callback function is called with two arguments—the
responseText
and
responseXML
:
function requestSuccess(responseText, responseXML) {
// do something with either supplied value
}
The
responseText
is the plain textual representation of the server's response. If the response
is a valid XML document, the
responseXML
parameter is a DOM tree containing the parsed
XML.
The
onSuccess
callback is a bit more complicated for
Request.HTML
objects:
function requestHTMLSuccess(responseTree, responseElements,
responseHTML, responseJavaScript) {
// do something with the data
}
The four parameters are:
➤
responseTree
: The node list of the response
➤
responseElements
: An array containing the elements of the response
➤
responseHTML
: The string content of the response
➤
responseJavaScript
: The JavaScript of the response
The
onSuccess
callback for
Request.JSON
objects is much simpler than
Request.HTML
's:
function requestJSONSuccess(responseJSON, responseText) {
// do something with the provided data
}
The
responseJSON
parameter is an object—the parsed JSON structure. So you won't need to
call
JSON.parse()
. The
responseText
parameter is the plaintext JSON structure. Honestly, your
authors don't know why you would need the
responseText
with
Request.JSON
, but it's there just
in case you need it (we don't think you will).
Let's use MooTools' Ajax utilities to modify the form validator from the previous chapter one last
time!
revisiting the Form Validator with Mootools
trY it out
Open your text editor and type the following: