Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate

Issue 162113002: Additions to HttpRequest docs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of $LIBRARYNAME; 5 part of $LIBRARYNAME;
6 6
7 /** 7 /**
8 * A client-side XHR request for getting data from a URL, 8 * A client-side XHR request for getting data from a URL,
9 * formally known as XMLHttpRequest. 9 * formally known as XMLHttpRequest.
10 * 10 *
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 /** 56 /**
57 * Creates a GET request for the specified [url]. 57 * Creates a GET request for the specified [url].
58 * 58 *
59 * The server response must be a `text/` mime type for this request to 59 * The server response must be a `text/` mime type for this request to
60 * succeed. 60 * succeed.
61 * 61 *
62 * This is similar to [request] but specialized for HTTP GET requests which 62 * This is similar to [request] but specialized for HTTP GET requests which
63 * return text content. 63 * return text content.
64 * 64 *
65 * To add query parameters, append them to the [url] following a `?`,
66 * joining each key to its value with `=` and separating key-value pairs with
67 * `&`.
68 *
69 * var name = Uri.encodeQueryComponent('John');
70 * var id = Uri.encodeQueryComponent('42');
71 * HttpRequest.getString('users.json?name=$name&id=$id')
72 * .then((HttpRequest resp) {
73 * // Do something with the response.
74 * });
75 *
65 * See also: 76 * See also:
66 * 77 *
67 * * [request] 78 * * [request]
68 */ 79 */
69 static Future<String> getString(String url, 80 static Future<String> getString(String url,
70 {bool withCredentials, void onProgress(ProgressEvent e)}) { 81 {bool withCredentials, void onProgress(ProgressEvent e)}) {
71 return request(url, withCredentials: withCredentials, 82 return request(url, withCredentials: withCredentials,
72 onProgress: onProgress).then((xhr) => xhr.responseText); 83 onProgress: onProgress).then((xhr) => xhr.responseText);
73 } 84 }
74 85
75 /** 86 /**
76 * Makes a server POST request with the specified data encoded as form data. 87 * Makes a server POST request with the specified data encoded as form data.
77 * 88 *
78 * This is roughly the POST equivalent of getString. This method is similar 89 * This is roughly the POST equivalent of getString. This method is similar
79 * to sending a FormData object with broader browser support but limited to 90 * to sending a FormData object with broader browser support but limited to
80 * String values. 91 * String values.
81 * 92 *
93 * If [data] is supplied, the key/value pairs are URI encoded with
94 * [Uri.encodeQueryComponent] and converted into an HTTP query string.
95 *
96 * Unless otherwise specified, this method appends the following header:
97 *
98 * Content-Type: application/x-www-form-urlencoded; charset=UTF-8
99 *
100 * Here's an example of using this method:
101 *
102 * var data = { 'firstName' : 'John', 'lastName' : 'Doe' };
103 * HttpRequest.postFormData('/send', data).then((HttpRequest resp) {
104 * // Do something with the response.
105 * });
106 *
82 * See also: 107 * See also:
83 * 108 *
84 * * [request] 109 * * [request]
85 */ 110 */
86 static Future<HttpRequest> postFormData(String url, Map<String, String> data, 111 static Future<HttpRequest> postFormData(String url, Map<String, String> data,
87 {bool withCredentials, String responseType, 112 {bool withCredentials, String responseType,
88 Map<String, String> requestHeaders, 113 Map<String, String> requestHeaders,
89 void onProgress(ProgressEvent e)}) { 114 void onProgress(ProgressEvent e)}) {
90 115
91 var parts = []; 116 var parts = [];
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 * (already) set in the header or 148 * (already) set in the header or
124 * [authorization headers](http://tools.ietf.org/html/rfc1945#section-10.2) 149 * [authorization headers](http://tools.ietf.org/html/rfc1945#section-10.2)
125 * should be specified for the request. Details to keep in mind when using 150 * should be specified for the request. Details to keep in mind when using
126 * credentials: 151 * credentials:
127 * 152 *
128 * * Using credentials is only useful for cross-origin requests. 153 * * Using credentials is only useful for cross-origin requests.
129 * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildca rd (*). 154 * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildca rd (*).
130 * * The `Access-Control-Allow-Credentials` header of `url` must be set to tru e. 155 * * The `Access-Control-Allow-Credentials` header of `url` must be set to tru e.
131 * * If `Access-Control-Expose-Headers` has not been set to true, only a subse t of all the response headers will be returned when calling [getAllRequestHeader s]. 156 * * If `Access-Control-Expose-Headers` has not been set to true, only a subse t of all the response headers will be returned when calling [getAllRequestHeader s].
132 * 157 *
158 * The following is equivalent to the [getString] sample above:
159 *
160 * var name = Uri.encodeQueryComponent('John');
161 * var id = Uri.encodeQueryComponent('42');
162 * HttpRequest.request('users.json?name=$name&id=$id')
163 * .then((HttpRequest resp) {
164 * // Do something with the response.
165 * });
166 *
167 * Here's an example of submitting an entire form with [FormData].
168 *
169 * var myForm = querySelector('form#myForm');
170 * var data = new FormData(myForm);
171 * HttpRequest.request('/submit', method: 'POST', sendData: data)
172 * .then((HttpRequest resp) {
173 * // Do something with the response.
174 * });
175 *
133 * Note that requests for file:// URIs are only supported by Chrome extensions 176 * Note that requests for file:// URIs are only supported by Chrome extensions
134 * with appropriate permissions in their manifest. Requests to file:// URIs 177 * with appropriate permissions in their manifest. Requests to file:// URIs
135 * will also never fail- the Future will always complete successfully, even 178 * will also never fail- the Future will always complete successfully, even
136 * when the file cannot be found. 179 * when the file cannot be found.
137 * 180 *
138 * See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access _authentication). 181 * See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access _authentication).
139 */ 182 */
140 static Future<HttpRequest> request(String url, 183 static Future<HttpRequest> request(String url,
141 {String method, bool withCredentials, String responseType, 184 {String method, bool withCredentials, String responseType,
142 String mimeType, Map<String, String> requestHeaders, sendData, 185 String mimeType, Map<String, String> requestHeaders, sendData,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 headers[key] = '${headers[key]}, $value'; 365 headers[key] = '${headers[key]}, $value';
323 } else { 366 } else {
324 headers[key] = value; 367 headers[key] = value;
325 } 368 }
326 } 369 }
327 return headers; 370 return headers;
328 } 371 }
329 372
330 $!MEMBERS 373 $!MEMBERS
331 } 374 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698