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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate b/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate
index a19ba4d79dfb8e24f7a66cda13319a3bf814ea3f..539e645ac913da012101119d036c7d38e6a7c542 100644
--- a/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate
+++ b/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate
@@ -62,6 +62,17 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
* This is similar to [request] but specialized for HTTP GET requests which
* return text content.
*
+ * To add query parameters, append them to the [url] following a `?`,
+ * joining each key to its value with `=` and separating key-value pairs with
+ * `&`.
+ *
+ * var name = Uri.encodeQueryComponent('John');
+ * var id = Uri.encodeQueryComponent('42');
+ * HttpRequest.getString('users.json?name=$name&id=$id')
+ * .then((HttpRequest resp) {
+ * // Do something with the response.
+ * });
+ *
* See also:
*
* * [request]
@@ -79,6 +90,20 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
* to sending a FormData object with broader browser support but limited to
* String values.
*
+ * If [data] is supplied, the key/value pairs are URI encoded with
+ * [Uri.encodeQueryComponent] and converted into an HTTP query string.
+ *
+ * Unless otherwise specified, this method appends the following header:
+ *
+ * Content-Type: application/x-www-form-urlencoded; charset=UTF-8
+ *
+ * Here's an example of using this method:
+ *
+ * var data = { 'firstName' : 'John', 'lastName' : 'Doe' };
+ * HttpRequest.postFormData('/send', data).then((HttpRequest resp) {
+ * // Do something with the response.
+ * });
+ *
* See also:
*
* * [request]
@@ -130,6 +155,24 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
* * The `Access-Control-Allow-Credentials` header of `url` must be set to true.
* * If `Access-Control-Expose-Headers` has not been set to true, only a subset of all the response headers will be returned when calling [getAllRequestHeaders].
*
+ * The following is equivalent to the [getString] sample above:
+ *
+ * var name = Uri.encodeQueryComponent('John');
+ * var id = Uri.encodeQueryComponent('42');
+ * HttpRequest.request('users.json?name=$name&id=$id')
+ * .then((HttpRequest resp) {
+ * // Do something with the response.
+ * });
+ *
+ * Here's an example of submitting an entire form with [FormData].
+ *
+ * var myForm = querySelector('form#myForm');
+ * var data = new FormData(myForm);
+ * HttpRequest.request('/submit', method: 'POST', sendData: data)
+ * .then((HttpRequest resp) {
+ * // Do something with the response.
+ * });
+ *
* Note that requests for file:// URIs are only supported by Chrome extensions
* with appropriate permissions in their manifest. Requests to file:// URIs
* will also never fail- the Future will always complete successfully, even
« 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