Index: sdk/lib/html/dart2js/html_dart2js.dart |
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart |
index 76d03b9c25631a481afab0dc88806a3ee4e589e4..0c038dac926bdae071ea45a99ee2e8ed3edccdcf 100644 |
--- a/sdk/lib/html/dart2js/html_dart2js.dart |
+++ b/sdk/lib/html/dart2js/html_dart2js.dart |
@@ -12590,6 +12590,69 @@ class HttpRequest extends EventTarget native "*XMLHttpRequest" { |
_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. |
+ */ |
+ static Future<String> getString(String url, |
+ {bool withCredentials}) { |
+ return request(url, withCredentials: withCredentials).then( |
+ (xhr) { |
+ return xhr.responseText; |
+ }); |
+ } |
+ |
+ /** |
+ * Creates a URL request for the specified `url`. |
+ * |
+ * By default this will do an HTTP GET request, this can be overridden with |
+ * [method]. |
+ * |
+ * The Future is completed when the response is available. |
+ */ |
+ 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; |
+ } |
+ |
+ |
@DomName('XMLHttpRequest.abort') |
@DocsEditable |
static const EventStreamProvider<ProgressEvent> abortEvent = const EventStreamProvider<ProgressEvent>('abort'); |