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 11efa7735db15c56e1a92a18ad47a123d1dac950..6bc98ead8d3d1bfa34d3c2f115c52eb7b3c7f9f8 100644 |
--- a/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate |
+++ b/tools/dom/templates/html/impl/impl_XMLHttpRequest.darttemplate |
@@ -61,5 +61,68 @@ $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
onComplete($CLASSNAME request)) => |
_HttpRequestUtils.get(url, onComplete, true); |
+ |
+ /** |
+ * Creates a URL get request for the specified `url`. |
+ * |
+ * The server response must be a `text/` mime type for this request to |
+ * succeed. |
Emily Fortuna
2013/01/31 01:04:15
might say in the docs how this is different from t
blois
2013/01/31 18:58:12
Done.
|
+ */ |
+ static Future<String> getString(String url, |
+ {bool withCredentials}) { |
+ return request(url, withCredentials: withCredentials).then( |
+ (xhr) { |
Jennifer Messerly
2013/01/31 04:12:17
maybe format this as:
(xhr) => xhr.responseText
?
blois
2013/01/31 18:58:12
Done.
|
+ return xhr.responseText; |
+ }); |
+ } |
+ |
+ /** |
+ * Creates a URL request for the specified `url`. |
Jennifer Messerly
2013/01/31 04:12:17
[url] ?
blois
2013/01/31 18:58:12
Done. Was mostly just following formatting from ex
|
+ * |
+ * By default this will do an HTTP GET request, this can be overridden with |
+ * [method]. |
+ * |
+ * The Future is completed when the response is available. |
+ */ |
Emily Fortuna
2013/01/31 01:04:15
since this method replaces the functionality of th
Jennifer Messerly
2013/01/31 04:12:17
I was wondering that too. They take callbacks inst
blois
2013/01/31 18:58:12
The primary benefit of the factories is that you c
|
+ static Future<HttpRequest> request(String url, |
+ {String method, bool withCredentials, String responseType, sendData}) { |
+ var completer = new Completer<String>(); |
+ |
+ var xhr = new HttpRequest(); |
+ if (method == null) { |
+ method = 'GET'; |
+ } |
+ xhr.open(method, url, true); |
+ |
+ if (withCredentials != null) { |
+ xhr.withCredentials = withCredentials; |
+ } |
+ |
+ if (responseType != null) { |
+ xhr.responseType = responseType; |
+ } |
+ |
+ xhr.onLoad.listen((e) { |
+ if (xhr.status >= 200 && xhr.status < 300 || |
+ xhr.status == 304 ) { |
+ completer.complete(xhr); |
+ } else { |
+ completer.completeError(e); |
+ } |
+ }); |
+ |
+ xhr.onError.listen((e) { |
+ completer.completeError(e); |
+ }); |
+ |
+ if (sendData != null) { |
+ xhr.send(sendData); |
+ } else { |
+ xhr.send(); |
+ } |
+ |
+ return completer.future; |
+ } |
+ |
$!MEMBERS |
} |