Request (aka Ajax)
Here is the documentation for Request.js.
The Request class is a relatively simple wrapper for the XMLHttpRequest object (the heart of Ajax functionality).
It takes the following options:
- url
- The URL to request (defaults to //null//; you can use the //send// method to specify the url later).
- method
- The HTTP method for the request, can be either 'post' (the default) or 'get'.
- data
- The default data for Request:send, used when no data is given. Defaults to ''.
- async
- If set to //false//, the requests will be synchronous and freeze the browser during request. Defaults to //true//.
- encoding
- The encoding to be set in the request header. Defaults to "utf-8".
- autoCancel
- When set to //true//, automatically cancels the already running request if another one is sent. Otherwise, ignores any new calls while a request is in progress. Defaults to //false//.
- headers
- An object to use in order to set the request headers.
- isSuccess
- Provide a function to override the built-in isSuccess function.
Then you'll need to call the .send method to actually initiate a request. .send takes two arguments, the url, and the data to send.
new Request({method: 'get'}).send('http://site.com/requestHandler.php?name=john&lastname=doe');
Element.send
MooTools has a "built-in" instance of Request that you can use to send a form with an ajax post request.
<form id="myForm" action="submit.php"> <input name="name" value="bob"> <input name="zipCode" value="90210"> </form> <script> $('myForm').send({onComplete: handleMyResponse}) </script>
You can use set to alter the options of the "built-in" version of Request:
$('myForm').set('send', { method: 'get' }); $('myForm').send();
mootorial/07-request/00-request.txt · Last modified: 2010/03/04 15:01 by aaron-n