/
request.html
178 lines (175 loc) · 5.8 KB
/
request.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta charset="utf-8">
<title>
MooTools
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="../assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="../assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css">
<link href="../assets/css/mootools.css" rel="stylesheet" type="text/css">
<link href="../assets/js/google-code-prettify/prettify.css" rel="stylesheet" type="text/css">
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body onload="prettyPrint()">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="../">MooTools</a>
<div class="nav-collapse">
<ul class="nav">
<li><a href="../">Home</a></li>
<li class="divider-vertical"></li>
<li class="active"><a href="">Documentation</a></li>
<li><a href="../learn/">Learn More</a></li>
<li class="divider-vertical"></li>
<li><a href="../download/">Download</a></li>
</ul>
</div>
<form class="navbar-search pull-right" action="../search/">
<input type="text" class="search-query span2" placeholder="Search">
</form>
<ul class="nav pull-right">
<li><a href="../plugins/">Plugins</a></li>
<li class="divider-vertical"></li>
<li><a href="../blog/">Blog</a></li>
<li class="divider-vertical"></li>
<li><a href="../community/">Community</a></li>
<li class="divider-vertical"></li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span3">
<ul class="nav nav-list">
<li class="nav-header">Documentation</li>
<li><a href="../docs/">Home</a></li>
<li class="divider"></li>
<li><a href="../docs/typeOf.html">typeOf</a></li>
<li class="divider"></li>
<li><a href="../docs/element.html">Element</a></li>
<li class="divider"></li>
<li><a href="../docs/each.html">each</a></li>
<li class="divider"></li>
<li><a href="../docs/setStyle.html">setStyle</a></li>
<li class="divider"></li>
<li class="active"><a href="../docs/request.html">Request</a></li>
</ul>
</div>
<div class="span9">
<ul class="breadcrumb">
<li><a href="../docs/">Docs</a> <span class="divider">/</span></li>
<li class="active">Request</li>
<li class="pull-right"><a href="#">Report a problem</a></li>
</ul>
<div class="page-header">
<h1>Request <small>Our Ajax wrapper</small></h1>
</div>
<p>The MooTools Ajax base class. If you only need to do something simple, then you may be able to use some of the <a href="#alternatives">simpler methods available</a>.</p>
<hr />
<h3>Syntax</h3>
<pre class="prettyprint">
var myRequest = new Request(<em>options</em>); // create the Request object
myRequest.send(); // send the request
</pre>
<div class="btn-group pull-right">
<p class="pull-left" style="line-height: 28px; padding-right: 10px;">Show Options:</p>
<button class="btn btn-primary">Basics</button>
<button class="btn">Properties</button>
<button class="btn">Events</button>
<button class="btn">All</button>
</div>
<hr style="clear: both" />
<dl class="dl-horizontal">
<dt>url</dt>
<dd><em>(string)</em> the url to request</dd>
<dt>method</dt>
<dd><em>(string)</em> The HTTP method for the request, can be either 'post' or 'get'. The default is 'post'.</dd>
<dt>data</dt>
<dd>
<em>(element, object or string)</em> the data to send as part of the request.
<hr />
<p>You can send a (single) element:</p>
<pre class="prettyprint">
data: $('myForm')
// If using a CSS selector, you need to select a single element, like so:
data: document.getElement('#myForm')
// You can't use $$ as that returns an *array* of elements
data: $$('#myForm') // doesn't work
</pre>
<p>You can use an object:</p>
<pre class="prettyprint">
data: {
value1: 'foo',
value2: 'bar'
}
</pre>
<p>Or you can pass a string.</p>
<pre class="prettyprint">
data: 'value1=foo&value2=bar'
</pre>
</dd>
<dt>onSuccess</dt>
<dd>
<em>(function)</em> An event that fires when the request is successful.
<hr />
<pre class="prettyprint">
onSuccess: function(responseText, responseXML){
// code goes here
}
</pre>
</dd>
</dl>
<hr />
<h3>Example:</h3>
<pre class="prettyprint">
new Request({
url: 'submit.php',
data: $('myForm'),
onSuccess: function(response){
alert(response);
}
}).send();
</pre>
<hr />
<h5 id="alternatives">Alternatives to Request</h5>
<ul>
<li>
<p>If you want to load HTML into an element easily, check out <a href="#">Element.load</a>.</p>
<pre class="prettyprint">
<div id="foo"></div>
$('foo').load('/content.php');
</pre>
</li>
<li>
<p>If you want to send a form easily, check out <a href="#">Element.send</a>.</p>
<pre class="prettyprint">
<form id="foo" method="post" action="submit.php">
<input type="text" name="bar" value="1" />
</form>
$('foo').send();
</pre>
</li>
</ul>
<hr />
<h5>Find out more</h5>
<p>Find out more about Request</p>
<ul>
<li><a href="#">View the source code</a></li>
<li><a href="../search/?query=Request">Search for <em>Request</em> on mootools.net</a></li>
</ul>
<hr />
<div class="well">
(comments)<br /><br /><br /><br /><br /><br /><br /><br /><br />
</div>
</div>
</div>
</div>
<script type="text/javascript" src="../assets/js/google-code-prettify/prettify.js"></script>
</body>
</html>