.travis.yml: Add Node 4, remove iojs.
[mootools.git] / Docs / Request / Request.HTML.md
blob6b86ddcca16882b2c0ccf224393dfe928ed97a58
1 Class: Request.HTML {#Request-HTML}
2 ===================================
4 Request Specifically made for receiving HTML.
6 ### Extends:
8 [Request][]
10 ### Syntax:
12         var myHTMLRequest = new Request.HTML([options]);
14 ### Arguments:
16 1. options - (*object*, optional) See options below.  Also inherited are all the options from [Request][].
18 ### Options:
20 * evalScripts  - (*boolean*: defaults to true) If set to true, `script` tags inside the response will be evaluated. This overrides the `false` default from Request.
21 * update - (*element*: defaults to null) The Element to insert the response text of the Request into upon completion of the request.
22 * append - (*element*: defaults to null) The Element to append the response text of the Request into upon completion of the request.
23 * filter - (*mixed*: defaults to null) To filter the response tree by a selector or function. See [Elements:filter][]
25 ### Events:
27 #### success
29 * (*function*) Function to execute when the HTML request completes. This overrides the signature of the Request success event.
31 ##### Signature:
33         onSuccess(responseTree, responseElements, responseHTML, responseJavaScript)
35 ##### Arguments:
37 1. responseTree           - (*element*) The node list of the remote response.
38 2. responseElements   - (*array*)   An array containing all elements of the remote response.
39 3. responseHTML           - (*string*)  The content of the remote response.
40 4. responseJavaScript - (*string*)  The portion of JavaScript from the remote response.
42 ### Returns:
44 * (*object*) A new Request.HTML instance.
46 ### Examples:
48 #### Simple GET Request:
50         var myHTMLRequest = new Request.HTML().get('myPage.html');
52 #### POST Request with data as String:
54         var myHTMLRequest = new Request.HTML({url: 'myPage.html'}).post('user_id=25&save=true');
56 #### Data from Object Passed via GET:
58         //Loads "load/?user_id=25".
59         var myHTMLRequest = new Request.HTML({url: 'load/'}).get({'user_id': 25});
61 #### Data from Element via POST:
63 ##### HTML
65         <form action="save/" method="post" id="user-form">
66                 <p>
67                         Search: <input type="text" name="search" />
68                         Search in description: <input type="checkbox" name="search_description" value="yes" />
69                         <input type="submit" />
70                 </p>
71         </form>
73 ##### JavaScript
75         //Needs to be in a submit event or the form handler.
76         var myHTMLRequest = new Request.HTML({url: 'save/'}).post($('user-form'));
78 ### See Also:
80 [Request][]
83 Object: Element.Properties {#Element-Properties}
84 ==============================================
86 see [Element.Properties][]
88 Element Property: load {#Element-Properties:load}
89 -------------------------------------------------
91 ### Setter
93 Sets a default Request.HTML instance for an Element.
95 #### Syntax:
97         el.set('load'[, options]);
99 #### Arguments:
101 1. options - (*object*) The Request options.
103 #### Returns:
105 * (*element*) The target Element.
107 #### Example:
109         el.set('load', {evalScripts: true});
110         el.load('some/request/uri');
113 ### Getter
115 Returns either the previously set Request.HTML instance or a new one with default options.
117 #### Syntax:
119         el.get('load');
121 #### Arguments:
123 1. property - (*string*) the Request.HTML property argument.
125 #### Returns:
127 * (*object*) The Request instance.
129 #### Example:
131         el.set('load', {method: 'get'});
132         el.load('test.html');
133         // the getter returns the Request.HTML instance, making its class methods available.
134         el.get('load').post('http://localhost/script');
138 Type: Element {#Element}
139 ========================
141 Custom Type to allow all of its methods to be used with any DOM element via the dollar function [$][].
143 Element Method: load {#Element:load}
144 ------------------------------------
146 Updates the content of the Element with a Request.HTML GET request.
148 ### Syntax:
150         myElement.load(url);
152 ### Arguments:
154 1. url - (*string*) The URL pointing to the server-side document.
156 ### Returns:
158 * (*element*) The target Element.
160 ### Example:
162 ##### HTML
164         <div id="content">Loading content...</div>
166 ##### JavaScript
168         $('content').load('page_1.html');
170 ### Cross-Origin Resource Sharing (CORS) note:
172 The Request.HTML class will (by default) add a custom header that, if used for a cross-origin request, will have to be reported as allowed in the preflight request, in addition to any other headers you may set yourself:
174         Access-Control-Allow-Headers: X-Requested-With
176 ### See Also:
178 - [$][], [Request](/core/Request/Request)
180 [Request]: /core/Request/Request
181 [$]: /core/Element/Element/#Window:dollar
182 [Element.Properties]: /core/Element/Element/#Element-Properties
183 [Elements:filter]: /core/Element/Element#Elements:filter