File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -547,12 +547,12 @@ function requestOkText(url) {
547
547
if (request .status === 200 ) {
548
548
deferred .resolve (request .responseText );
549
549
} else {
550
- onerror ( );
550
+ deferred . reject ( new Error ( " Status code was " + request . status ) );
551
551
}
552
552
}
553
553
554
554
function onerror () {
555
- deferred .reject (" Can't XHR " + JSON .stringify (url));
555
+ deferred .reject (new Error ( " Can't XHR " + JSON .stringify (url) ));
556
556
}
557
557
558
558
function onprogress (event ) {
@@ -563,6 +563,21 @@ function requestOkText(url) {
563
563
}
564
564
```
565
565
566
+ Below is an example of how to use this `` requestOkText `` function:
567
+
568
+ ``` javascript
569
+ requestOkText (" http://localhost:3000" )
570
+ .then (function (responseText ) {
571
+ // If the HTTP response returns 200 OK, log the response text.
572
+ console .log (responseText);
573
+ }, function (error ) {
574
+ // If there's an error or a non-200 status code, log the error.
575
+ console .error (error);
576
+ }, function (progress ) {
577
+ // Log the progress as it comes in.
578
+ console .log (" Request progress: " + Math .round (progress * 100 ) + " %" );
579
+ });
580
+ ```
566
581
567
582
### The Middle
568
583
You can’t perform that action at this time.
0 commit comments